Hi,
Could anyone please help me before I go mad trying to do file uploads in php.
I am using a simple form and script to try to upload files, based on the php manual (as well as numerous other sites I have seen that duplicate the code). Here is a sample of the script just to print the filename of the selected file:
<?php
if ($_POST['submit'])
{
//Extract data
print "Filename: ";
print $_FILES['userfile']['tmp_name'];
print "<br />Realname: ";
print $_FILES['userfile']['name'];
}?>
<form enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
<input type="file" name="userfile" size="35" /><br />
<input type="submit" value="Send File" name="submit" />
</form>
The problem seems to be that the $_FILES array is not getting set to anything, as using print_r($_FILES); results in "Array(0)".
This is the case both on my hosting providers server, and my own personal server running php 4.2.
Any help or hint as to why this isn't working would be appreciated!
Thanks,
Chrisyou don't have an action in your form.
Could anyone please help me before I go mad trying to do file uploads in php.
I am using a simple form and script to try to upload files, based on the php manual (as well as numerous other sites I have seen that duplicate the code). Here is a sample of the script just to print the filename of the selected file:
<?php
if ($_POST['submit'])
{
//Extract data
print "Filename: ";
print $_FILES['userfile']['tmp_name'];
print "<br />Realname: ";
print $_FILES['userfile']['name'];
}?>
<form enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
<input type="file" name="userfile" size="35" /><br />
<input type="submit" value="Send File" name="submit" />
</form>
The problem seems to be that the $_FILES array is not getting set to anything, as using print_r($_FILES); results in "Array(0)".
This is the case both on my hosting providers server, and my own personal server running php 4.2.
Any help or hint as to why this isn't working would be appreciated!
Thanks,
Chrisyou don't have an action in your form.