1

我最近一直在运行响应式文件管理器,无论是在我的本地机器上还是在托管服务器上,都收到了不同的问题,尽管代码是相同的。这些问题都与文件的上传有关——目前测试的文件都是JPEG文件,大于2MB的JPEG文件无法上传。

共享问题:

对于本地机器和托管服务器,如果上传的图像超过 8MB,那么我会收到以下错误消息:

上传的文件超过了允许的最大大小

本地机器问题:

仅对于本地机器,如果上传的图像大于 2MB 但小于 8MB,我会收到以下错误消息:

警告:mime_content_type():第 92 行 C:\xampp\htdocs\project\webroot\3rdparty\responsive 文件管理器\filemanager\upload.php 中的空文件名或路径

其中第 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 以查看我的版本是否已过时,但事实并非如此。
4

1 回答 1

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']);
    }
}
于 2017-09-13T03:28:46.357 回答