通过bluimp上传jQuery文件,如何替换而不是重命名 [英] jQuery File Upload by bluimp, how to replace instead of renaming

查看:66
本文介绍了通过bluimp上传jQuery文件,如何替换而不是重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先可以在这里找到jQuery插件:

First of all the jQuery plugin can be found here:

https://github.com/blueimp/jQuery-File-Up

我正在使用脚本的PHP版本,并且试图替换具有相同名称的图像,而不是重命名它们.

I'm using the PHP-version of the script and I'm trying to replace images that has the same name instead of renaming them.

我想我已经找到了进行重命名的功能,但是我尝试的编辑不起作用.

I think I've found the functions that do the renaming, but the edits I tried do not work.

  protected function upcount_name_callback($matches) {
        $index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
        $ext = isset($matches[2]) ? $matches[2] : '';
        return ' ('.$index.')'.$ext;
    }

    protected function upcount_name($name) {
        return preg_replace_callback(
            '/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/',
            array($this, 'upcount_name_callback'),
            $name,
            1
        );
    }

有什么建议吗?我在整个地方都搜索了此搜索,但无济于事.

Any suggestions? I've searched for this all over the place but to no avail.

链接到执行上传的php类: https://github.com/blueimp /jQuery-File-Upload/blob/master/server/php/upload.class.php

Link to the php class that does the upload: https://github.com/blueimp/jQuery-File-Upload/blob/master/server/php/upload.class.php

有什么建议吗?

我试图在这些函数上返回null,但这只是挂起了脚本,可能是因为如果文件名相同,它不知道该怎么办.

I've tried to just return null on these functions, but that just hangs the script, probably because it doesn't know what to do if the filename is the same.

推荐答案

您可以更改其PHP服务器端脚本以覆盖文件,而不必创建新的唯一文件名.只需更改上传处理程序类函数get_file_name:

You can alter their PHP server side script to have files overwritten instead of creating a new unique filename. Just alter upload handler class function get_file_name:

原始功能:

 protected function get_file_name($file_path, $name, $size, $type, $error,
        $index, $content_range) {
    $name = $this->trim_file_name($file_path, $name, $size, $type, $error,
        $index, $content_range);
    return $this->get_unique_filename(
        $file_path,
        $this->fix_file_extension($file_path, $name, $size, $type, $error,
            $index, $content_range),
        $size,
        $type,
        $error,
        $index,
        $content_range
    );
}

将其更改为此:

protected function get_file_name($file_path, $name, $size, $type, $error,
            $index, $content_range) {
        $name = $this->trim_file_name($file_path, $name, $size, $type, $error,
            $index, $content_range);
        return $name;
    }

如果上传的文件名与服务器上的现有文件相同,则现有文件将被覆盖.

This way existing file will get overwritten if the uploaded file-name is same as the existing file on your server.

这篇关于通过bluimp上传jQuery文件,如何替换而不是重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆