Page 1 of 1
[SOLVED] $_FILES doesn't work
Posted: Sun Apr 17, 2011 3:57 am
by rockline
Dear all,
I've just installed EasyPHP 5.3.6 (Windows) and created a small webpage to upload a file.
However, the $_FILES command seems not to work. Any idea?
Here is my html:
Code: Select all
<form action="bb2.php" method="post" name="form1" enctype="multipart/form-data">
<input type="file" name="form_lettingsphoto1"><br>
<input type="submit" value="ADD LETTING" name="form_lettingssubmit">
</form>
Here is my second page (in php):
Code: Select all
<?php
print '<pre>';
print_r($_FILES);
print '</pre>';
move_uploaded_file($_FILES['form_lettingsphoto1']['name'], 'toto.jpg');
?>
print_r($_FILES) doesn't return anything and the file I parse through the html page is not copied into the new folder.
Thanks.
Best regards.
Re: $_FILES doesn't work
Posted: Sun Apr 17, 2011 4:23 am
by Darhazer
Code: Select all
move_uploaded_file($_FILES['form_lettingsphoto1']['name'], 'toto.jpg');
has to be
Code: Select all
move_uploaded_file($_FILES['form_lettingsphoto1']['tmp_name'], 'toto.jpg');
As for the first issue, check if your file is not bigger than any of
max_upload_size
max_post_size
memory_limit
settings in php.ini
Re: $_FILES doesn't work
Posted: Sun Apr 17, 2011 4:36 am
by rockline
Hi Darhazer,
Thanks for the reply.
My file is 25kb. I changed my script to what you mentioned but still doesn't work.
I left the settings by default:
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
post_max_size = 8M
memory_limit = 128M
Re: $_FILES doesn't work
Posted: Sun Apr 17, 2011 10:40 am
by fugix
25 kb is fine. i would try using a definite path to the jpg file. I'm also not sure if the file must already exist before it inserts the data into it or if it can make the file...I would also check permissions on the file you wish to store the image in
Re: $_FILES doesn't work
Posted: Mon Apr 18, 2011 2:10 pm
by pickle
You may need the MAX_FILE_SIZE element set, as shown here:
http://www.php.net/manual/en/features.f ... method.php
Re: $_FILES doesn't work
Posted: Mon Apr 18, 2011 2:12 pm
by fugix
the default MAX_FILE_SIZE is 2MB...so 25 kb is no problem unless the MAX_FILE_SIZE was tampered with
Re: $_FILES doesn't work
Posted: Mon Apr 18, 2011 2:19 pm
by pickle
Your form doesn't have a MAX_FILE_SIZE element, so it doesn't get POSTed. Some (all? most?) installations don't provide the $_FILES array if $_POST['MAX_FILE_SIZE'] isn't set.
Re: $_FILES doesn't work
Posted: Mon Apr 18, 2011 3:15 pm
by fugix
try to take out the space in your file input name...
Re: $_FILES doesn't work
Posted: Mon Apr 18, 2011 4:43 pm
by Darhazer
Your form doesn't have a MAX_FILE_SIZE element, so it doesn't get POSTed. Some (all? most?) installations don't provide the $_FILES array if $_POST['MAX_FILE_SIZE'] isn't set.
I've never used it, so most installation (all?) does not require it

but
rockline, it's worth trying it, maybe your installation ... is little different.
Also, give us the output of $_POST
fugix, there is no space in the field name?
Re: $_FILES doesn't work
Posted: Mon Apr 18, 2011 5:00 pm
by fugix
yeah..didnt see the underscore..my fault
Re: $_FILES doesn't work
Posted: Tue Apr 19, 2011 4:01 am
by rockline
Hi guys,
Just found the issue (from another forum): I had forgotten to add the following line on top of my php file:
isset($_FILES['form_lettingsphoto1']);
I'm not sure to understand why this line is compulsory but it seems to fix my issue.
Thanks anyway for the help.
Best regards.