Skip to content

Commit 0305154

Browse files
committed
customizable upload parameter name #44
1 parent 085e17f commit 0305154

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

src/Api/AwsS3Api.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function actionInitiate()
4747
],
4848
'upload' => [
4949
'fileSizeLimit' => $this->storage->config('upload.fileSizeLimit'),
50+
'paramName' => $this->storage->config('upload.paramName'),
5051
],
5152
'viewer' => [
5253
'absolutePath' => $this->storage->config('viewer.absolutePath'),
@@ -192,8 +193,9 @@ public function actionUpload()
192193

193194
$itemData = null;
194195
$responseData = [];
196+
$paramName = $this->storage->config('upload.paramName');
195197
$content = $this->storage->initUploader($model)->post(false);
196-
$files = isset($content['files']) ? $content['files'] : null;
198+
$files = isset($content[$paramName]) ? $content[$paramName] : null;
197199

198200
// there is only one file in the array as long as "singleFileUploads" is set to "true"
199201
if ($files && is_array($files) && is_object($files[0])) {

src/Api/LocalApi.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function actionInitiate()
4343
],
4444
'upload' => [
4545
'fileSizeLimit' => $this->storage->config('upload.fileSizeLimit'),
46+
'paramName' => $this->storage->config('upload.paramName'),
4647
],
4748
'viewer' => [
4849
'absolutePath' => $this->storage->config('viewer.absolutePath'),
@@ -189,8 +190,9 @@ public function actionUpload()
189190

190191
$itemData = null;
191192
$responseData = [];
193+
$paramName = $this->storage->config('upload.paramName');
192194
$content = $this->storage->initUploader($model)->post(false);
193-
$files = isset($content['files']) ? $content['files'] : null;
195+
$files = isset($content[$paramName]) ? $content[$paramName] : null;
194196

195197
// there is only one file in the array as long as "singleFileUploads" is set to "true"
196198
if ($files && is_array($files) && is_object($files[0])) {

src/Repository/Local/UploadHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct($options = null, $initialize = false, $error_message
3535
$this->storage = $this->options['storage'];
3636

3737
$this->options['upload_dir'] = $this->model->getAbsolutePath();
38-
$this->options['param_name'] = 'files';
38+
$this->options['param_name'] = $this->storage->config('upload.paramName');
3939
$this->options['readfile_chunk_size'] = 10 * 1024 * 1024;
4040
$this->options['max_file_size'] = $this->storage->config('upload.fileSizeLimit');
4141
// ItemModel::checkWritePermission() is used instead of this regex check

src/Repository/S3/UploadHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct($options = null, $initialize = false, $error_message
3535
$this->storage = $this->options['storage'];
3636

3737
$this->options['upload_dir'] = $this->model->getAbsolutePath();
38-
$this->options['param_name'] = 'files';
38+
$this->options['param_name'] = $this->storage->config('upload.paramName');
3939
$this->options['readfile_chunk_size'] = 10 * 1024 * 1024;
4040
$this->options['max_file_size'] = $this->storage->config('upload.fileSizeLimit');
4141
// ItemModel::checkWritePermission() is used instead of this regex check

src/config/config.local.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@
178178
* If set to "true" files will be overwritten on uploads if they have same names, otherwise an index will be added.
179179
*/
180180
"overwrite" => false,
181+
/**
182+
* Upload parameter name, that is expected to contains uploaded file data - $_FILES[paramName].
183+
* Good usecase example is CKEditor image upload plugin, that sends files within "upload" name.
184+
*/
185+
"paramName" => "upload",
181186
],
182187
/**
183188
* Images section

0 commit comments

Comments
 (0)