【发布时间】:2018-02-21 14:02:29
【问题描述】:
我最近在本地计算机和托管服务器上都运行了响应式文件管理器,尽管代码相同,但它们都收到了不同的问题。这些问题都与文件上传有关——目前测试的文件都是JPEG文件,大于2MB的JPEG文件无法上传。
共享问题:
对于本地机器和托管服务器,如果上传的图像超过 8MB,我会收到以下错误消息:
上传的文件超过了允许的最大大小
本地机器问题:
仅对于本地机器,如果上传的图片大于 2MB 但小于 8MB,我会收到以下错误消息:
警告:mime_content_type():C:\xampp\htdocs\project\webroot\3rdparty\responsive file manager\filemanager\upload.php 中第 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
}
}
我也收到此错误:
不允许文件扩展名。 (@C:\xampp\htdocs\project\webroot\3rdparty\responsive 文件管理器\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();
}
}
服务器问题:
在服务器上,这两个问题被这个单一的错误所取代:
内存不足
(@/home/site/public_html/webroot/3rdparty/responsive 文件管理器/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();
}
}
}
}
目前的尝试:
我看过以下内容:
- 由于本地计算机上的文件扩展名问题,我检查了 config.php 文件中允许的文件扩展名,但 jpeg 的两种格式都已经存在:
'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,
- 我还检查了最新版本的 config.php 和 upload.php 以查看我的版本是否已过时,但事实并非如此。
【问题讨论】:
-
tempnam('/tmp','RF')生成模板文件,如:/tmp/RF123.tmp因此函数mime_content_type无法确定 mime 类型...对于服务器问题,我们不知道哪个函数填充变量$memory_error跨度> -
mime_content_type($_FILES['file']['tmp_name']);是错误的,因为tmp_name是没有扩展名的文件,你应该检查name而不是explode(".", strtolower($temp))返回一个数组而不是字符串 -
如果我将
mime_content_type($_FILES['file']['tmp_name']);更改为mime_content_type($_FILES['file']['name']);,我会收到此错误:mime_content_type(testimage.JPG): failed to open stream: No such file or directory in C:\xampp\htdocs\project\webroot\3rdparty\responsive file manager\filemanager\upload.php on line 92,而文件扩展名不允许错误仍然存在。我刚刚在我的问题帖子中添加了$memory_error来自服务器问题的位置。 -
好吧,对不起,我收回了,函数
mime_content_type没有很好的文档记录...在mime_content_type之前尝试echo $_FILES['file']['tmp_name']; -
您的意思是不是如下:
$mime_type = echo mime_content_type($_FILES['file']['tmp_name']);或$mime_type = mime_content_type(echo $_FILES['file']['tmp_name']);- 无论哪种方式,都会导致语法错误;第一个说Expected: expression,第二个说Expected: )
标签: php file-upload responsive-filemanager