Skip to content
Advertisement

File upload PHP JPG issues

I’m getting confused while working with an file upload HTML form and some PHP to handle the input. In the form i have two file selects for images. When uploading an .png file i can get the file size etc using $_FILES. But when i’m trying to upload an .jpg file, i can’t get more then the filename, no size, type, temporary name.

And when uploading two files at once, .png and .jpg, everything works for the .png file but not the .jpg.

What am i missing here? Are there any “restrictions when using $_FILES with .jpg filetypes or something else that i’m not aware of?

Example code:

    if (isset($_FILES['upload1'])) {            // JPG FILE
        $fileName1 = $_FILES['upload1']['name'];
        $fileSize1 = $_FILES['upload1']['size'];
        echo $fileName1;
        echo $fileSize1;
    }
    if (isset($_FILES['upload2'])) {            // PNG FILE
        $fileName2 = $_FILES['upload2']['name'];
        $fileSize2 = $_FILES['upload2']['size'];
        echo $fileName2;
        echo $fileSize2;
    }

outputs something like (without the brackets):

"filename1.jpg" "0" "filename2.png" "12313"

print_r($_FILES) outputs:
Array (
[upload1] => Array (
[name] => volvo1.png
[type] => image/png
[tmp_name] => C:wamptmpphp14AD.tmp
[error] => 0
[size] => 6380 )

[upload2] => Array (
[name] => IMG0379.JPG
[type] => [tmp_name] =>
[error] => 1
[size] => 0 )
)

Advertisement

Answer

Issue solved, for those that might encounter the same issue, the solution is as easy as to change the upload_max_filesize in php.ini.

php.ini can be found under:

  1. Ubuntu: /etc/php/5.6/apache2/php.ini
  2. Windows: C:xamppphpphp.ini
  3. Mac: /usr/local/etc/php/8.1/php.ini

or you can even do php -i | grep php.ini

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement