Page 1 of 1

multipart/form-data

Posted: Wed May 28, 2003 2:32 am
by navid
hi all
i will upload a file with form .
I have a problem to do it.
when I submitted the form if my form content enctype="multipart/form-data" the all of the fild's form not pass by post method.
I work on Unix and apachi

my script is:
----------
<?php
if(isset($HTTP_FILES_VARS['f1']))
echo "ok";
else
echo "no";
?>
<form action="test_form.php" enctype="multipart/form-data" method="post">
<input type="file" name="f1">
<input type="submit" name="sub">
</form>


BUT if my form haven't enctype="multipart/form-data" then i have all variable.

i don't know it.
please help me

Posted: Wed May 28, 2003 4:09 am
by sleepingdanny
You don't need to use: $HTTP_FILES_VARS['f1']
You can just write: $f1
:P

Code: Select all

<?php
if(isset($f1)){
echo "ok";
}
else{
echo "no"; 
}
?>

Code: Select all

&lt;form action="" enctype="multipart/form-data" method="post"&gt; 
&lt;input type="file" name="f1"&gt; 
&lt;input type="submit" name="sub"&gt; 
&lt;/form&gt;

Posted: Wed May 28, 2003 4:46 am
by volka
$f1 will only be available if register_globals is enabled, which is deprecated and might not be supported in future versions of php.

as a small example to see what is stored where when using multipart/form-data try

Code: Select all

<html>
	<body>
<?php
	if (count($_FILES) > 0)
	{
?>
		<fieldset><legend>contents of array $_FILES</legend>
			<pre><?php print_r($_FILES); ?></pre>
		</fieldset>
<?php		
	}

	if (count($_POST) > 0)
	{
?>
		<fieldset><legend>contents of array $_POST</legend>
			<pre><?php print_r($_POST); ?></pre>
		</fieldset>
<?php		
	}
?>
		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">
			<p>
				<input type="file" name="f1" />
				<input type="checkbox" name="c1" id="c1" /><label for="c1">are you sure?</label>
				<br />
				<input type="text" name="comment" id="comment"><label for="comment">your comment</label>
				<br />
				<input type="submit" />
			</p>
		</form>
	</body>
</html>