简体   繁体   English

文件上传PHP JPG问题

[英]File upload PHP JPG issues

I'm getting confused while working with an file upload HTML form and some PHP to handle the input.我在使用文件上传 HTML 表单和一些 PHP 来处理输入时感到困惑。 In the form i have two file selects for images.在表单中,我有两个图像文件选择。 When uploading an .png file i can get the file size etc using $_FILES.上传 .png 文件时,我可以使用 $_FILES 获取文件大小等。 But when i'm trying to upload an .jpg file, i can't get more then the filename, no size, type, temporary name.但是当我尝试上传 .jpg 文件时,我无法获得更多的文件名,没有大小,类型,临时名称。

And when uploading two files at once, .png and .jpg, everything works for the .png file but not the .jpg.当一次上传两个文件 .png 和 .jpg 时,一切都适用于 .png 文件,但不适用于 .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?将 $_FILES 与 .jpg 文件类型或其他我不知道的东西一起使用时是否有任何限制?

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: print_r($_FILES) 输出:
Array (大批 (
[upload1] => Array ( [上传 1] => 数组 (
[name] => volvo1.png [名称] => volvo1.png
[type] => image/png [类型] => 图像/png
[tmp_name] => C:\\wamp\\tmp\\php14AD.tmp [tmp_name] => C:\\wamp\\tmp\\php14AD.tmp
[error] => 0 [错误] => 0
[size] => 6380 ) [尺寸] => 6380 )

[upload2] => Array ( [上传 2] => 数组 (
[name] => IMG0379.JPG [名称] => IMG0379.JPG
[type] => [tmp_name] => [类型] => [tmp_name] =>
[error] => 1 [错误] => 1
[size] => 0 ) [尺寸] => 0 )
) )

问题已解决,对于那些可能遇到相同问题的人来说,解决方案就像更改 php.ini 中的 upload_max_filesize 一样简单。

Markus right, change the upload_max_filesize in /etc/php/7.3/apache2/php.ini马库斯对了,修改/etc/php/7.3/apache2/php.ini中的upload_max_filesize

; 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM