1
votes

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:\wamp\tmp\php14AD.tmp
[error] => 0
[size] => 6380 )

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

2
please print_r($_FILES) and check the whole array.Maulik Vora
Check if there perhaps was an error during upload. There should be a value indicating that. var_dump($_FILES); to see all of it.Halcyon
Maybe the JPG is too big. Anything in $_FILES['upload1']['error'];?Pekka
Aha, found out that the error 1 is indicating on an file size error.Markus
@halfer - Sadly i cant do that for another two days. I'll come back and take care of it when i am able to.Markus

2 Answers

3
votes

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.

0
votes

Markus right, change the upload_max_filesize in /etc/php/7.3/apache2/php.ini

; http://php.net/upload-max-filesize
upload_max_filesize = 200M

if still not, maybe install these library

apt-get install -y libpng-dev 
apt-get install -y    libwebp-dev 
apt-get install -y    libjpeg62-turbo-dev 
apt-get install -y    libjpeg-dev 
apt-get install -y    libpng-dev libxpm-dev 
apt-get install -y    libfreetype6-dev