【问题标题】:jQuery File Upload 'undefined' image urljQuery 文件上传“未定义”图片网址
【发布时间】:2013-08-25 14:11:25
【问题描述】:

我正在使用一个名为jQuery file upload 的插件将图像上传到页面。目前它以原始图像名称作为文件名(IMG_1234)上传。我需要服务器上的图像名称的特定格式(例如1.123456.jpg

我发现这个 PHP 代码可用于更改图像名称:

class CustomUploadHandler extends UploadHandler
{
    protected function trim_file_name($name, $type) {
        $name = time()."_1";
        $name = parent::trim_file_name($name, $type);
        return $name;
    }
}

当我上传一张图片时,它被正确命名,但图片预览的链接是undefined。这会阻止我通过插件删除图像。

变量data.urlundefined...如果我回到不重命名图像的原始代码,一切正常。

有没有人对这个插件有任何帮助的经验?谢谢!

编辑:

我至少发现了部分问题...返回下载链接(也用于删除)的功能是提供原始文件名,而不是更新后的文件名。我对 PHP 类真的很陌生,所以我不确定变量的来源以及如何修复它。如果能得到任何帮助,我将不胜感激!

这是该函数的 PHP 代码:

protected function get_download_url($file_name, $version = null, $direct = false) {
    if (!$direct && $this->options['download_via_php']) {
        $url = $this->options['script_url']
            .$this->get_query_separator($this->options['script_url'])
            .'file='.rawurlencode($file_name);
            //  The `$file_name` variable is the original image name (`IMG_1234`), and not the renamed file.  
        if ($version) {
            $url .= '&version='.rawurlencode($version);
        }
        return $url.'&download=1';
    }
    if (empty($version)) {
        $version_path = '';
    } else {
        $version_url = @$this->options['image_versions'][$version]['upload_url'];
        if ($version_url) {
            return $version_url.$this->get_user_path().rawurlencode($file_name);
        }
        $version_path = rawurlencode($version).'/';
    }
    return $this->options['upload_url'].$this->get_user_path()
        .$version_path.rawurlencode($file_name);
}

编辑 2:我认为这与选项中的 'param_name' => 'files', 有关。有人知道这是做什么的吗?

【问题讨论】:

    标签: php javascript jquery file upload


    【解决方案1】:

    通过编辑UploadHandler.php 中的trim_file_name 函数而不是扩展index.php 中的类来修复它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      • 2019-07-04
      • 1970-01-01
      • 2014-02-03
      • 2022-09-25
      相关资源
      最近更新 更多