【问题标题】:cannot upload and save large image files on PHP server无法在 PHP 服务器上上传和保存大图像文件
【发布时间】:2015-07-04 08:47:51
【问题描述】:

我已经编写了 php 上传图片文件到 php 服务器。 100kB以内的小图片,就是成功。 但是当超过 500KB 时,它就失败了,并说服务器上没有收到数据。 我也不知道为什么。此上传的 php 服务器中没有保存文件。 你知道怎么解决吗??

function uploadImages($input, $file)
{

    if($input == null || $input == "")
    {
        return false;
    }
    $stringVal = $input; 
    $value  = str_replace('data:image/png;base64,', '', $stringVal);

    if ($this->check_base64_image($value) == false) {
        return false;
    }

    $actualFile  = base64_decode($value);
    $img = imagecreatefromstring($actualFile);
    $imgSize = getimagesize('data://application/octet-stream;base64,' . base64_encode($actualFile));


    if ($img == false) {
        return false;
    }else
    {

        /*** maximum filesize allowed in bytes ***/
        $max_file_length  = 100000;

        log_message('debug', 'PRE UPLOADING!!!!!!!!');

        if (isset($img)){

            log_message('debug', 'UPLOADING!!!!!!!!');

            // check the file is less than the maximum file size
            if($imgSize['0'] > $max_file_length || $imgSize['1'] > $max_file_length)
            {
                log_message('debug', 'size!!!!!!!!'.print_r($imgSize));
                $messages = "File size exceeds $max_file_size limit";
                return false;
            }else if (file_exists($file)) {
                return false;
            }else
            {
                file_put_contents($file, $actualFile);
                return true;
            }
        }       
    } 
}

【问题讨论】:

  • 出于安全原因 php 使用大小限制。您可以静态或动态地更改它。如果您不更改使用默认值,这可能会解释您的问题。

标签: php image upload


【解决方案1】:

试试这个,

ini_set('post_max_size',52428800); // 50 MB
ini_set('upload_max_filesize',52428800) // 50 MB

【讨论】:

  • 它说:Request Entity Too Large 请求的资源/index.php/newPost/不允许使用GET请求请求数据,或者请求中提供的数据量超过了容量限制。此外,在尝试使用 ErrorDocument 处理请求时遇到 500 Internal Server Error 错误。
猜你喜欢
  • 1970-01-01
  • 2012-02-13
  • 1970-01-01
  • 1970-01-01
  • 2014-03-27
  • 1970-01-01
  • 2011-07-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多