Page 1 of 1

$HTTP_POST_FILES

Posted: Wed Feb 14, 2007 10:41 pm
by nikii
hello friends im new to this forum...
i want to know how $HTTP_POST_FILES works... i know how to use it and how to work with it. but i have a very small question i have not yet found the answer on the NET i did a search more then 6 hour. but found nothing and finally decided to ask here..
my question goes here....
i know when an ARRAY of $_HTTP_POST_FILES is processed.
it is processed like this...
$HTTP_POST_FILES['file1']['name'];
$HTTP_POST_FILES['file1']['tmp_name'];
$HTTP_POST_FILES['file1']['size'];
$HTTP_POST_FILES['file1']['name'];
$HTTP_POST_FILES['file1']['error'];
i want to know how values are Assigned by the Browser to this Array.

let me explain
when we use this code in our html form

Code: Select all

<form enctype="multipart/form-data" action="uploader1.php" method="post">
 <input type="hidden" name="MAX_FILE_SIZE" value="1024" />
 Send this file: <input name="userfile" type="file" />
 <input type="submit" value="Send File" />
</form>
the browser assign the value

Code: Select all

1024 to the Variable MAX_FILE_SIZE
if we are using get method for any type of processing the values are passed using QueryString.
like

Code: Select all

http://somesite.com/page.php?lname=Adam&lname=Neal
i know we can not use GET method with $_FILES

now i want to know how the values are assigned to the $_FILES Array by the browser...

Posted: Wed Feb 14, 2007 10:53 pm
by superdezign
I'm sorry, but it seems as though whatever you are asking, you claim to already know the answer to. $_FILES contains everything you've mentioned.

Are you asking if there is a difference between $_FILES when using a get method as opposed to a post method?

Posted: Thu Feb 15, 2007 5:38 am
by nikii
superdezign wrote: Are you asking if there is a difference between $_FILES when using a get method as opposed to a post method?
Thanks for your Reply superdezign
As far as i think we can not use $_FILES using GET method...
but what if we can upload a file using GET method...
then how the QueryString will be for the Action URL..
if there is a way of using GET method for $HTTP_POST_FILES so let me know...
:roll:

Posted: Thu Feb 15, 2007 5:48 am
by volka
$HTTP_POST_FILES. There's nothing like that for GET.

Posted: Thu Feb 15, 2007 6:04 am
by nikii
volka wrote:$HTTP_POST_FILES. There's nothing like that for GET.
i want to know how values are assigned to the Variables?
to

Code: Select all

$HTTP_POST_FILES['FileVar']['name']
if we are using this code

Code: Select all

<form enctype="multipart/form-data" action="uploader1.php" method="post"> 
 <input type="hidden" name="MAX_FILE_SIZE" value="1024" /> 
 Send this file: <input name="userfile" type="file" /> 
 <input type="submit" value="Send File" /> 
</form>
then Value to MAX_FILE_SIZE=1024 will be assigned when form is POSTED.
i just want to know how values are assigned to USERFILE variable ?
will it be like this?
userfile=c:\somepath ?
then how about the size, name, tmp_name etc...
+++
how $HTTP_POST_FILES will recieve these values?
$HTTP_POST_FILES['c:\somepath']['????']
hope u can understand my problem now...
if u can not understand my problem please let me know i will try to explain...
thanks for ur valuable replies...

Posted: Thu Feb 15, 2007 6:05 am
by Oren

Posted: Thu Feb 15, 2007 6:14 am
by volka

Code: Select all

<form method="get" action="xyz.php">
	<input type="hidden" name="abc" value="123" />
	<input type="hidden" name="kmn" value="456" />
	<input type="submit" />
</form>
when this form is submitted the client/browser takes all the (successful) named elements and append them as key=value paris to the url, in this case resulting in xyz.php?abc=123&kmn=456
php parses these parameters and assign them to the superglobal $_GET.

Almost the same with

Code: Select all

<form method="post" action="xyz.php">
	<input type="hidden" name="abc" value="123" />
	<input type="hidden" name="kmn" value="456" />
	<input type="submit" />
</form>
except the parameters are not appended to the url but are sent in the request body. That's like the response document (e.g. a html page) is transfered, just the other way round, client->server.
If you now add a input/file element, the user picks a file and the form is submitted, the browser will read the contents of the file and append it to the request body. The default value=pair transfer mechanism isn't sufficient for file transfers. That's why you set enctype="multipart/form-data" and that's how php detects the file upload.