【问题标题】:Prestashop upload product image failedPrestashop 上传产品图片失败
【发布时间】:2014-04-07 12:57:00
【问题描述】:

从我的本地主机上传 prestashop 到服务器后,出现了一个问题 尝试上传产品图片时出现此错误“服务器文件大小与本地文件大小不同”

在 prestashop 文件中搜索后,我发现上传器类负责上传过程。

public function upload($file, $dest = null)
{
    if ($this->validate($file))
    {
        if (isset($dest) && is_dir($dest))
            $file_path = $dest;
        else
            $file_path = $this->getFilePath(isset($dest) ? $dest : $file['name']);

        if ($file['tmp_name'] && is_uploaded_file($file['tmp_name'] ))
                move_uploaded_file($file['tmp_name'] , $file_path);
        else
            // Non-multipart uploads (PUT method support)
            file_put_contents($file_path, fopen('php://input', 'r'));

        $file_size = $this->_getFileSize($file_path, true);

        if ($file_size === $file['size'])
        {
            $file['save_path'] = $file_path;
        }
        else
        {
            $file['size'] = $file_size;
            unlink($file_path);
            $file['error'] = Tools::displayError('Server file size is different from local file size');
        }
    }

    return $file;
}

当评论 if 语句女巫负责比较文件大小并上传图片时,我收到了这个错误

“复制图片时出错,文件不存在了。”

我把img文件夹权限改成777还是一样的问题?

【问题讨论】:

    标签: php prestashop


    【解决方案1】:

    这是一个权限问题。我通过提供对缓存和主题文件夹的完全访问权限 (777) 解决了这个问题。

    如果这没有帮助,请尝试授予对所有文件的完全访问权限。出于安全原因,请务必将文件夹的权限改回 755,文件的权限改回 644。

    【讨论】:

      【解决方案2】:

      请将“ if ($file_size === $file['size']) ”改为“ if ($file_size = $file['size']) ”

      这个方法对我有用。

      【讨论】:

      • 您在此处分配 $file_size,它应该始终返回 true。我不认为这能达到你想要的效果。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-25
      相关资源
      最近更新 更多