[SOLVED] $_FILES doesn't work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rockline
Forum Newbie
Posts: 3
Joined: Sun Apr 17, 2011 3:52 am

[SOLVED] $_FILES doesn't work

Post 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.
Last edited by rockline on Tue Apr 19, 2011 4:02 am, edited 1 time in total.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: $_FILES doesn't work

Post 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
rockline
Forum Newbie
Posts: 3
Joined: Sun Apr 17, 2011 3:52 am

Re: $_FILES doesn't work

Post 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
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: $_FILES doesn't work

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: $_FILES doesn't work

Post by pickle »

You may need the MAX_FILE_SIZE element set, as shown here: http://www.php.net/manual/en/features.f ... method.php
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: $_FILES doesn't work

Post by fugix »

the default MAX_FILE_SIZE is 2MB...so 25 kb is no problem unless the MAX_FILE_SIZE was tampered with
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: $_FILES doesn't work

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: $_FILES doesn't work

Post by fugix »

try to take out the space in your file input name...
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: $_FILES doesn't work

Post 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?
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: $_FILES doesn't work

Post by fugix »

yeah..didnt see the underscore..my fault
rockline
Forum Newbie
Posts: 3
Joined: Sun Apr 17, 2011 3:52 am

Re: $_FILES doesn't work

Post 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.
Post Reply