Responsive File Manager upload issues

6.2k views Asked by At

I've been running the Responsive File Manager recently, both on my local machine as well as a hosted server and have received different issues for each, despite the code being the same. These issues are all related to the uploading of files - currently the tested files have all been only JPEG files, where JPEG files larger than 2 MB are not able to be uploaded.

Shared issues:

For both local machine & hosted server, if the uploaded image exceeds 8MB, then I receive the following error message:

The uploaded file exceeds the max size allowed

Local machine issues:

For the local machine only, if the uploaded image is greater than 2MB but less than 8MB, I receive the following error message:

Warning: mime_content_type(): Empty filename or path in C:\xampp\htdocs\project\webroot\3rdparty\responsive file manager\filemanager\upload.php on line 92

where line 92 refers to this specific line within a set of if statements:

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
    }
}

I also receive this error as well:

File extension is not allowed. (@C:\xampp\htdocs\project\webroot\3rdparty\responsive file manager\filemanager\upload.php#260)

which refers to this set of if statements:

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();
    }
}

Server issues:

On the server, those two issues are replaced by this single error:

Not enough Memory
(@/home/site/public_html/webroot/3rdparty/responsive file manager/filemanager.upload.php#241)

which refers to this set of if statements:

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();
            }
        }
    }
}

Attempts so far:

I've looked at the following:

  • With the file extensions issue on my local machine, I checked the allowed file extensions in the config.php file, but both formats of jpeg were already there:

'ext_img' => array( 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'svg' ), //Images

Meanwhile in include\mime_type_lib.php, both formats of jpeg were already there:

$mime_types = array(
    'jpeg'    => 'image/jpeg',
    'jpg'     => 'image/jpeg',
)
  • On my local machine, I increased the upload_max_filesize to 128M. Meanwhile on the server, I used cPanel's PHP settings to do the same thing. Additionally in the config.php file, I changed the MaxSizeUpload setting to match the above changes as follows:

'MaxSizeUpload' => 128,

  • I did also check against the latest version of config.php and upload.php to see if my versions were outdated, but that wasn't the case.
1

There are 1 answers

8
Kazz On

Try this:

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']);
    }
}