我最近在我的本地计算机和托管服务器上运行了响应式文件管理器,并且每个都收到了不同的问题,尽管代码是相同的。这些问题都与上传文件有关 - 目前测试的文件都只是JPEG文件,大于2 MB的JPEG文件无法上传。
共享问题:
对于本地机器和托管服务器,如果上传的图像超过8MB,则会收到以下错误消息:
The uploaded file exceeeds the max size allowed.
本地机器问题:
仅对于本地计算机,如果上载的映像大于2MB但小于8MB,则会收到以下错误消息:
Warning: mime_content_type(): Empty filename or path in C:\xampp\htdocs\project\webroot\3rdparty\responsive file manager\filemanager\upload.php on line 92.
其中第92行引用一组if语句中的这一特定行:
if ( ! empty($_FILES) || isset($_POST['url']))
{
if(isset($_POST['url'])){
$temp = tempnam('/tmp','RF');
$handle = fopen($temp, "w");
fwrite($handle, file_get_contents($_POST['url']));
fclose($handle);
$_FILES['file']= array(
'name' => basename($_POST['url']),
'tmp_name' => $temp,
'size' => filesize($temp),
'type' => explode(".", strtolower($temp))
);
}
$info = pathinfo($_FILES['file']['name']);
$mime_type = $_FILES['file']['type'];
if (function_exists('mime_content_type')){
$mime_type = mime_content_type($_FILES['file']['tmp_name']); //line 92
}
}
我也收到了这个错误:
File extension is not allowed. (@C:\xampp\htdocs\project\webroot\3rdparty\responsive file manager\filemanager\upload.php#260)
引用这组if语句:
if ( ! empty($_FILES) || isset($_POST['url']))
{
else // file ext. is not in the allowed list
{
response(trans("Error_extension").AddErrorLocation(), 406)->send(); //line 260
exit();
}
}
服务器问题:
在服务器上,这两个问题被这个错误所取代:
Not enough Memory
(@/home/site/public_html/webroot/3rdparty/responsive file manager/filemanager.upload.php#241)
引用这组if语句:
if ( ! empty($_FILES) || isset($_POST['url']))
{
if (in_array(fix_strtolower($extension), $ext))
{
if ($is_img)
{
$memory_error = FALSE;
if ( $extension != 'svg' && !create_img($targetFile, $targetFileThumb, 122, 91))
{
$memory_error = TRUE;
}
// not enough memory
if ($memory_error)
{
unlink($targetFile);
response(trans("Not enought Memory").AddErrorLocation(), 406)->send(); //line 241
exit();
}
}
}
}
到目前为止尝试:
我看过以下内容:
'ext_img' => array( 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'svg' ), //Images
同时在include \ mime_type_lib.php中,两种格式的jpeg已经存在:
$mime_types = array(
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
)
upload_max_filesize
增加到128M。同时在服务器上,我使用cPanel的PHP设置来做同样的事情。另外在config.php文件中,我更改了MaxSizeUpload设置以匹配上述更改,如下所示: 'MaxSizeUpload' => 128,
答案 0 :(得分:0)
试试这个:
if ( ! empty($_FILES) || isset($_POST['url']))
{
if(isset($_POST['url'])){
if(FALSE === ($temp = tempnam('/tmp','RF'))){
response(trans("Failed to create temporary file").AddErrorLocation(), 406)->send();
exit();
}
$handle = fopen($temp, "w");
fwrite($handle, file_get_contents($_POST['url']));
fclose($handle);
$explUrl = explode(".", basename($_POST['url']));
$suffix = array_pop($explUrl);
$_FILES['file']= array(
'name' => basename($_POST['url']),
'tmp_name' => $temp,
'size' => filesize($temp),
// type should be mime-type not file suffix
'type' => $suffix,
'error' => UPLOAD_ERR_OK
);
}
if($_FILES['file']['error'] !== UPLOAD_ERR_OK){
response(trans("Error upload code: ".$_FILES['file']['error']).AddErrorLocation(), 406)->send();
// error code list: http://php.net/manual/en/features.file-upload.errors.php
exit();
}
if(empty($_FILES['file']['tmp_name'])){
response(trans("Error upload").AddErrorLocation(), 406)->send();
exit();
}
$info = pathinfo($_FILES['file']['name']);
$mime_type = $_FILES['file']['type'];
if (function_exists('mime_content_type')){
$mime_type = mime_content_type($_FILES['file']['tmp_name']);
}
}