首先,可以在这里找到jQuery插件:
https://github.com/blueimp/jQuery-File-Upload
我正在使用PHP版本的脚本,我正在尝试替换具有相同名称的图像而不是重命名它们.
我想我已经找到了重命名的功能,但我尝试的编辑不起作用.
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
);
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?我在这个地方搜索过这个但是无济于事.
链接到执行上传的php类:https: //github.com/blueimp/jQuery-File-Upload/blob/master/server/php/upload.class.php
有什么建议?
编辑:
我试图在这些函数上返回null,但这只是挂起脚本,可能是因为如果文件名是相同的,它不知道该怎么做.
您可以更改其PHP服务器端脚本以覆盖文件,而不是创建新的唯一文件名.只需更改上传处理程序类功能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
);
}
Run Code Online (Sandbox Code Playgroud)
改变它:
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;
}
Run Code Online (Sandbox Code Playgroud)
这样,如果上载的文件名与服务器上的现有文件相同,则现有文件将被覆盖.