diff --git a/app/Http/Controllers/Publish/IndexController.php b/app/Http/Controllers/Publish/IndexController.php index af01bc2..61b394a 100644 --- a/app/Http/Controllers/Publish/IndexController.php +++ b/app/Http/Controllers/Publish/IndexController.php @@ -271,7 +271,7 @@ class IndexController extends Controller $files = count($request->file('files')) - 1; foreach (range(0, $files) as $index) { // $rules['files.' . $index] = 'image|max:2048'; - $rules['files.' . $index . '.file'] = ['required', 'file', new RdrFiletypes(), new RdrFilesize($index + 1)]; + $rules['files.' . $index . '.file'] = ['required', new RdrFiletypes(), new RdrFilesize($index + 1)]; } } $validator = Validator::make($request->all(), $rules); diff --git a/app/Http/Controllers/Publish/SubmitController.php b/app/Http/Controllers/Publish/SubmitController.php index 732df07..f099ce4 100644 --- a/app/Http/Controllers/Publish/SubmitController.php +++ b/app/Http/Controllers/Publish/SubmitController.php @@ -98,16 +98,7 @@ class SubmitController extends Controller public function delete($id): RedirectResponse { $dataset = Dataset::with('files')->findOrFail($id); - if ($dataset->server_state != "inprogress" || $dataset->server_state != "rejected_editor") { - session()->flash( - 'flash_message', - 'You cannot delete this datastet!' - . ' There status of this dataset is ' - . $dataset->server_state - . ' !' - ); - return redirect()->route('settings.project'); - } else { + if ($dataset->server_state == "inprogress" || $dataset->server_state == "rejected_editor") { if ($dataset->files->count() > 0) { foreach ($dataset->files as $file) { if (isset($file->path_name)) { @@ -117,7 +108,16 @@ class SubmitController extends Controller } $dataset->delete(); session()->flash('flash_message', 'You have deleted 1 dataset!'); - return redirect()->route('publish.workflow.index'); + return redirect()->route('publish.workflow.submit.index'); + } else { + session()->flash( + 'flash_message', + 'You cannot delete this datastet!' + . ' There status of this dataset is ' + . $dataset->server_state + . ' !' + ); + return redirect()->route('publish.workflow.submit.index'); } } diff --git a/app/Rules/RdrFilesize.php b/app/Rules/RdrFilesize.php index 0e82bc8..4d0ad75 100644 --- a/app/Rules/RdrFilesize.php +++ b/app/Rules/RdrFilesize.php @@ -16,7 +16,8 @@ class RdrFilesize implements Rule */ public function __construct($fileIndex) { - $this->maxFileSize = Config::get('enums.max_filesize'); + $this->maxFileSize = $this->maximumUploadSize(); + //ini_get('upload_max_filesize');// Config::get('enums.max_filesize');//10240 $this->fileIndex = $fileIndex; } @@ -32,7 +33,7 @@ class RdrFilesize implements Rule //return Rule::in($this->filetypes); // $upload_max_size = ini_get('upload_max_filesize'); $fileSize = filesize($value); - return $fileSize <= $this->maxFileSize * 1024; + return $fileSize <= $this->maxFileSize; // return $this->getSize($attribute, $value) <= $this->maxFileSize; } @@ -45,6 +46,51 @@ class RdrFilesize implements Rule { return 'file number '. $this->fileIndex .' is too large for the destination storage system.'; } + + /** + * The maximum file upload size by getting PHP settings + * @return integer|float file size limit in BYTES based + */ + private function maximumUploadSize() + { + static $upload_size = null; + if ($upload_size === null) { + $post_max_size = $this->returnBytes('post_max_size'); + $upload_max_filesize = $this->returnBytes('upload_max_filesize'); + $memory_limit = $this->returnBytes('memory_limit'); + // Even though we disable all of variables in php.ini. These still use default value + // Nearly impossible but check for sure + if (empty($post_max_size) && empty($upload_max_filesize) && empty($memory_limit)) { + return false; + } + $upload_size = min($post_max_size, $upload_max_filesize, $memory_limit); + } + return $upload_size; + } + + private function returnBytes($val) + { + $value = ini_get($val); + + // Value must be a string. + if (!is_string($value)) { + return false; + } + preg_match('/^(?\d+)(?