PHP PNG图像与哑剧“ image / jpeg”一起上传到KCFINDER 3.12

问题描述 投票:1回答:1

在这一点上,我对名为this-thing.png(从photoshop CS5中创建为PNG24)的图像感到困惑,并将其作为kcfinder上传到kcfinder

image/jpeg

enter image description here进行分析,显示图像完全是100%PNG

TriID

但是当$ _ FILES [(key($ _ FILES)] ['tmp_name']中的变量数据到达kcfinder \ core \ class \ browser.php函数moveUploadFile(as参数$ file)... tmp_name中的mime类型显示为JPEG而不是PNG。

出于测试目的,已修改的功能,包含C:\TrID>trid C:\users\michael\downloads\this-thing.png TrID/32 - File Identifier v2.20 - (C) 2003-15 By M.Pontello Definitions found: 3790 Analyzing... Collecting data from file: C:\users\michael\downloads\this-thing.png 100.0% (.PNG) Portable Network Graphics (16000/1) 中的代码

getimagesize() not returning false

结果,在文件this-thing.png]上传期间,表明媒体类型实际上是JPG而不是PNG(这是一部分,我不能似乎缠住我的头)。

protected function moveUploadFile($file, $dir) { $message = $this->checkUploadedFile($file); if ($message !== true) { if (isset($file['tmp_name'])) @unlink($file['tmp_name']); return "{$file['name']}: $message"; } $filename = $this->normalizeFilename($file['name']); $target = "$dir/" . file::getInexistantFilename($filename, $dir); echo "<h3>PHP_FILES foreach</h3>"; foreach ($_FILES['upload']['name'] as $key => $value){ echo "<pre>"; print_r(getimagesize($_FILES['upload']['tmp_name'][$key])); echo "</pre>"; } echo "<h3>TEMP FILE</h3>"; echo "</strong>file variable</strong>"; echo "<pre>"; print_r($file); echo "</pre>"; echo "</strong>file.tmp_name</strong>"; echo "<pre>"; print_r($file['tmp_name']); echo "</pre>"; $tmp_name_imagesize = getimagesize($file['tmp_name']); echo "<pre>"; print_r($tmp_name_imagesize); echo "</pre>"; if (imagetypes() & IMG_PNG) { echo "PNG Supported"; } else { echo "PNG not supported."; } // mkaatman - move tmp file to /tmp/ to check its MD5SUM result $temporary_file_path = $file['tmp_name'] . ".uploaded"; move_uploaded_file($file['tmp_name'], $temporary_file_path); die(); } (来源:enter image description here

显然,此文件iforce.co.nz是上传到php92C2.tmp.uploaded目录的文件。

/tmp/

为了文件分析,我已使用enter image description here在文件末尾添加了.png

Windows Rename

但是如果图像是通过PHP直接测试的(将复制内容粘贴到目录中)

C:\TrID>trid C:\users\michael\downloads\php92C2.tmp.uploaded.png

TrID/32 - File Identifier v2.20 - (C) 2003-15 By M.Pontello
Definitions found:  3790
Analyzing...

Collecting data from file: C:\users\michael\downloads\php92C2.tmp.uploaded.png
 50.0% (.JPG) JFIF JPEG Bitmap (4003/3)
 37.4% (.JPG) JPEG Bitmap (3000/1)
 12.4% (.MP3) MP3 audio (1000/1)

结果显示图像实际上是PNG。

<?php

$image_file = "this-thing.png";
$image_file_details = getimagesize($image_file);

echo "<pre>";
print_r($image_file_details);
echo "</pre>";

?>

kcfinder / cache / base.js

函数中使用的表单function _.initUploadButton = function()是您的基本上载表单。
Array
(
    [0] => 800
    [1] => 300
    [2] => 3
    [3] => width="800" height="300"
    [bits] => 8
    [mime] => image/png
)

最后是来自<div id="upload" style="top:5px;width:77px;height:31px"> <form enctype="multipart/form-data" method="post" target="uploadResponse" action="browse.php?type=image&lng=en&opener=ckeditor&act=upload"><input type="file" name="upload[]" onchange="_.uploadFile(this.form)" style="height:31px" multiple="multiple" /><input type="hidden" name="dir" value="" /></form> </div> 的KCFINDER.Config的一些信息

php

基于所有这些信息,我似乎无法弄清楚为什么地球上以PNG格式上传的图像又以JPEG格式返回。

编辑:我已经测试过,kcfinder使用了从mspaint创建的图像(这是令人困惑的地方)

经过测试的PNG图像。

CONFIG.imageDriversPriority imagick gmagick gd CONFIG.deniedExts exe com msi bat php phps phtml php3 php4 cgi pl htaccess htm html CONFIG.types Array ( [image] => 7z aiff asf avi bmp csv doc fla flv gif gz gzip jpeg jpg mid mov mp3 mp4 mpc mpeg mpg ods odt pdf png ppt pxd qt ram rar rm rmi rmvb rtf sdc sitd swf sxc sxw tar tgz tif tiff txt vsd wav wma wmv xls xml zip [images] => 7z aiff asf avi bmp csv doc fla flv gif gz gzip jpeg jpg mid mov mp3 mp4 mpc mpeg mpg ods odt pdf png ppt pxd qt ram rar rm rmi rmvb rtf sdc sitd swf sxc sxw tar tgz tif tiff txt vsd wav wma wmv xls xml zip [files] => 7z aiff asf avi bmp csv doc fla flv gif gz gzip jpeg jpg mid mov mp3 mp4 mpc mpeg mpg ods odt pdf png ppt pxd qt ram rar rm rmi rmvb rtf sdc sitd swf sxc sxw tar tgz tif tiff txt vsd wav wma wmv xls xml zip [uploads] => 7z aiff asf avi bmp csv doc fla flv gif gz gzip jpeg jpg mid mov mp3 mp4 mpc mpeg mpg ods odt pdf png ppt pxd qt ram rar rm rmi rmvb rtf sdc sitd swf sxc sxw tar tgz tif tiff txt vsd wav wma wmv xls xml zip [mimages] => *mime image/gif image/png image/jpeg )

结果(基于上面的代码)。

enter image description here

enter image description here

编辑:PNG支持(回复神射手)

C:\TrID>trid C:\users\michael\Pictures\breaking-bad.png

TrID/32 - File Identifier v2.20 - (C) 2003-15 By M.Pontello
Definitions found:  3790
Analyzing...

Collecting data from file: C:\users\michael\Pictures\breaking-bad.png
100.0% (.PNG) Portable Network Graphics (16000/1)

C:\TrID>

编辑:我发现图像从PNG转换为JPG

如果if (imagetypes() & IMG_PNG) { echo "PNG Supported"; } else { echo "PNG not supported."; } checkUploadedFile期间被注释掉,则文件moveUploadFile以预期的PNG格式出现。...

this-thing.png

输出为protected function checkUploadedFile(array $aFile=null) { $config = &$this->config; $file = ($aFile === null) ? $this->file : $aFile; if (!is_array($file) || !isset($file['name'])) return $this->label("Unknown error"); if (is_array($file['name'])) { foreach ($file['name'] as $i => $name) { $return = $this->checkUploadedFile(array( 'name' => $name, 'tmp_name' => $file['tmp_name'][$i], 'error' => $file['error'][$i] )); if ($return !== true) return "$name: $return"; } return true; } $extension = file::getExtension($file['name']); $typePatt = strtolower(text::clearWhitespaces($this->types[$this->type])); // CHECK FOR UPLOAD ERRORS if ($file['error']) return ($file['error'] == UPLOAD_ERR_INI_SIZE) ? $this->label("The uploaded file exceeds {size} bytes.", array('size' => ini_get('upload_max_filesize'))) : ( ($file['error'] == UPLOAD_ERR_FORM_SIZE) ? $this->label("The uploaded file exceeds {size} bytes.", array('size' => $_GET['MAX_FILE_SIZE'])) : ( ($file['error'] == UPLOAD_ERR_PARTIAL) ? $this->label("The uploaded file was only partially uploaded.") : ( ($file['error'] == UPLOAD_ERR_NO_FILE) ? $this->label("No file was uploaded.") : ( ($file['error'] == UPLOAD_ERR_NO_TMP_DIR) ? $this->label("Missing a temporary folder.") : ( ($file['error'] == UPLOAD_ERR_CANT_WRITE) ? $this->label("Failed to write file.") : $this->label("Unknown error.") ))))); // HIDDEN FILENAMES CHECK elseif (substr($file['name'], 0, 1) == ".") return $this->label("File name shouldn't begins with '.'"); // EXTENSION CHECK elseif ( (substr($file['name'], -1) == ".") || !$this->validateExtension($extension, $this->type) ) return $this->label("Denied file extension."); // SPECIAL DIRECTORY TYPES CHECK (e.g. *img) elseif (preg_match('/^\*([^ ]+)(.*)?$/s', $typePatt, $patt)) { list($typePatt, $type, $params) = $patt; $class = __NAMESPACE__ . "\\type_$type"; if (class_exists($class)) { $type = new $class(); $cfg = $config; $cfg['filename'] = $file['name']; if (strlen($params)) $cfg['params'] = trim($params); $response = $type->checkFile($file['tmp_name'], $cfg); if ($response !== true) return $this->label($response); } else return $this->label("Non-existing directory type."); } // IMAGE RESIZE $img = image::factory($this->imageDriver, $file['tmp_name']); if (!$img->initError && !$this->imageResize($img, $file['tmp_name'])) return $this->label("The image is too big and/or cannot be resized."); return true; }

[目前,我对名为this-thing.png的图像(从photoshop CS5中创建为PNG24)感到困惑,并以image / jpeg的形式上传到kcfinder。用TriID分析,显示图像为...

php xampp mime jquery-file-upload kcfinder
1个回答
0
投票

我遇到的这是一个非常令人困惑的问题。但是我设法解决了。

© www.soinside.com 2019 - 2024. All rights reserved.