Image Upload with PHP Returning an Error: Undefined index error

Asked

Viewed 195 times

2

Good evening everyone, I am using a script that I have and that I always used to upload images only when I choose some images it returns the error undefined index error

the only problem is that in 80% of cases works normal I did a var dump from $_FILES to see what happens

in the normal case

array (size=1)
  'foto' => 
    array (size=5)
      'name' => string 'interlogo.jpg' (length=13)
      'type' => string 'image/jpeg' (length=10)
      'tmp_name' => string 'C:\wamp\tmp\php586.tmp' (length=22)
      'error' => int 0
      'size' => int 13800

in the case of error

array (size=0)
  empty

the only difference from one photo to another is the size, one has 130k and another 3 mega. when gives the error it gives well in the lines of the variables

$foto_name=$_FILES["foto"]["name"];
$foto=$_FILES["foto"]["tmp_name"];  

someone has already made this mistake ?

  • 1

    Check the values upload_max_filesize and post_max_size in his php.ini. If the values are smaller than the file you are trying to upload, the global variable $_FILES will be empty.

  • I checked and both are with 20 mega being that the file only has 3

  • the post size was in 2 places in php.ini one with 3 mega other with 20 , solved. Thank you

  • Even with your problem solved, I published a slightly more detailed answer, so if someone has the same problem as yours and finds your question, they will have the most visible solution.

1 answer

1


Your problem may be with the directive post_max_size of php.ini.

According to the documentation:

[...] If the posted data is larger than post_max_size then the variables superglobals $_POST and $_FILES will be empty. [...]

It is also worth checking the directive upload_max_filesize, since to upload large files, the max_post_size must be greater than upload_max_filesize.

  • thanks for the effort ^^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.