Skip to content

Commit f44f773

Browse files
committed
Support passing a list of files to the delete method. Closes blueimp#2505
The format follows the upload file name parameter scheme: DELETE /server/php?files[]=cat.jpg&files[]=dog.jpg
1 parent 7a61038 commit f44f773

1 file changed

Lines changed: 36 additions & 14 deletions

File tree

server/php/UploadHandler.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* jQuery File Upload Plugin PHP Class 6.8.1
3+
* jQuery File Upload Plugin PHP Class 6.9.0
44
* https://github.com/blueimp/jQuery-File-Upload
55
*
66
* Copyright 2010, Sebastian Tschan
@@ -225,7 +225,8 @@ protected function get_download_url($file_name, $version = null, $direct = false
225225
protected function set_additional_file_properties($file) {
226226
$file->deleteUrl = $this->options['script_url']
227227
.$this->get_query_separator($this->options['script_url'])
228-
.'file='.rawurlencode($file->name);
228+
.$this->get_singular_param_name()
229+
.'='.rawurlencode($file->name);
229230
$file->deleteType = $this->options['delete_type'];
230231
if ($file->deleteType !== 'DELETE') {
231232
$file->deleteUrl .= '&_method=DELETE';
@@ -786,8 +787,22 @@ protected function get_version_param() {
786787
return isset($_GET['version']) ? basename(stripslashes($_GET['version'])) : null;
787788
}
788789

790+
protected function get_singular_param_name() {
791+
return substr($this->options['param_name'], 0, -1);
792+
}
793+
789794
protected function get_file_name_param() {
790-
return isset($_GET['file']) ? basename(stripslashes($_GET['file'])) : null;
795+
$name = $this->get_singular_param_name();
796+
return isset($_GET[$name]) ? basename(stripslashes($_GET[$name])) : null;
797+
}
798+
799+
protected function get_file_names_params() {
800+
$params = isset($_GET[$this->options['param_name']]) ?
801+
$_GET[$this->options['param_name']] : array();
802+
foreach ($params as $key => $value) {
803+
$params[$key] = basename(stripslashes($value));
804+
}
805+
return $params;
791806
}
792807

793808
protected function get_file_type($file_path) {
@@ -884,7 +899,7 @@ public function get($print_response = true) {
884899
$file_name = $this->get_file_name_param();
885900
if ($file_name) {
886901
$response = array(
887-
substr($this->options['param_name'], 0, -1) => $this->get_file_object($file_name)
902+
$this->get_singular_param_name() => $this->get_file_object($file_name)
888903
);
889904
} else {
890905
$response = array(
@@ -950,20 +965,27 @@ public function post($print_response = true) {
950965
}
951966

952967
public function delete($print_response = true) {
953-
$file_name = $this->get_file_name_param();
954-
$file_path = $this->get_upload_path($file_name);
955-
$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
956-
if ($success) {
957-
foreach($this->options['image_versions'] as $version => $options) {
958-
if (!empty($version)) {
959-
$file = $this->get_upload_path($file_name, $version);
960-
if (is_file($file)) {
961-
unlink($file);
968+
$file_names = $this->get_file_names_params();
969+
if (empty($file_names)) {
970+
$file_names = array($this->get_file_name_param());
971+
}
972+
$response = array();
973+
foreach($file_names as $file_name) {
974+
$file_path = $this->get_upload_path($file_name);
975+
$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
976+
if ($success) {
977+
foreach($this->options['image_versions'] as $version => $options) {
978+
if (!empty($version)) {
979+
$file = $this->get_upload_path($file_name, $version);
980+
if (is_file($file)) {
981+
unlink($file);
982+
}
962983
}
963984
}
964985
}
986+
$response[$file_name] = $success;
965987
}
966-
return $this->generate_response(array('success' => $success), $print_response);
988+
return $this->generate_response($response, $print_response);
967989
}
968990

969991
}

0 commit comments

Comments
 (0)