From 629ef90722456dadf175abbd368f1e6b003d854d Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sun, 13 Oct 2019 01:08:13 +0900 Subject: [PATCH] Update storage.php --- system/storage.php | 131 +++++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 65 deletions(-) diff --git a/system/storage.php b/system/storage.php index f87e7be..e324dc6 100644 --- a/system/storage.php +++ b/system/storage.php @@ -2,6 +2,7 @@ /** * @file storage.php * @date 2018-05-27 + * @updated 2019-10-13 * @author Go Namhyeon * @brief Stroage module for ReasonableFramework */ @@ -74,76 +75,76 @@ if(!check_function_exists("get_storage_url")) { } if(!check_function_exists("move_uploaded_file_to_storage")) { - function move_uploaded_file_to_stroage($options=array()) { - $response = array( - "files" => array() - ); + function move_uploaded_file_to_stroage($options=array()) { + $response = array( + "files" => array() + ); - $requests = get_requests(); - $files = $requests['_FILES']; + $requests = get_requests(); + $files = $requests['_FILES']; - $storage_type = get_value_in_array("storage_type", $options, "data"); - $upload_base_path = get_storage_path($storage_type); - $upload_base_url = get_storage_url($storage_type); + $storage_type = get_value_in_array("storage_type", $options, "data"); + $upload_base_path = get_storage_path($storage_type); + $upload_base_url = get_storage_url($storage_type); - if(!array_key_empty("only_image", $options)) { - $upload_allow_ext = array( - "png", "gif", "jpg", "jpeg", "tif" - ); - } elseif(!array_key_empty("only_docs", $options)) { - $upload_allow_ext = array( - "png", "gif", "jpg", "jpeg", "tif", - "xls", "ppt", "doc", "xlsx", "pptx", - "docx", "odt", "odp", "ods", "xlsm", - "tiff", "pdf", "xlsm" - ); - } elseif(!array_key_empty("only_audio", $options)) { - $upload_allow_ext = array( - "mp3", "ogg", "m4a", "wma", "wav" - ); - } else { - $upload_allow_ext = array(); - } + if(!array_key_empty("only_image", $options)) { + $upload_allow_ext = array( + "png", "gif", "jpg", "jpeg", "tif" + ); + } elseif(!array_key_empty("only_docs", $options)) { + $upload_allow_ext = array( + "png", "gif", "jpg", "jpeg", "tif", + "xls", "ppt", "doc", "xlsx", "pptx", + "docx", "odt", "odp", "ods", "xlsm", + "tiff", "pdf", "xlsm" + ); + } elseif(!array_key_empty("only_audio", $options)) { + $upload_allow_ext = array( + "mp3", "ogg", "m4a", "wma", "wav" + ); + } else { + $upload_allow_ext = array(); + } - foreach($files as $k=>$file) { - $upload_ext = get_file_extension($files[$k]['name']); - $upload_name = make_random_id(32) . (empty($upload_ext) ? "" : "." . $upload_ext); - $upload_file = $upload_base_path . "/" . $upload_name; - $upload_url = $upload_base_url . "/" . $upload_name; + foreach($files as $k=>$file) { + $upload_ext = get_file_extension($files[$k]['name']); + $upload_name = make_random_id(32) . (empty($upload_ext) ? "" : "." . $upload_ext); + $upload_file = $upload_base_path . "/" . $upload_name; + $upload_url = $upload_base_url . "/" . $upload_name; - if(count($upload_allow_ext) == 0 || in_array($upload_ext, $upload_allow_ext)) { - if(move_uploaded_file($files[$k]['tmp_name'], $upload_file)) { - // get file source name - $upload_source_name = $files[$k]['name']; - if(strlen($upload_source_name) == 0) { - $upload_source_name = $upload_name; - } + if(count($upload_allow_ext) == 0 || in_array($upload_ext, $upload_allow_ext)) { + if(move_uploaded_file($files[$k]['tmp_name'], $upload_file)) { + // get file source name + $upload_source_name = $files[$k]['name']; + if(strlen($upload_source_name) == 0) { + $upload_source_name = $upload_name; + } - // make file data - $response['files'][$k] = array( - "storage_type" => $storage_type, - "upload_ext" => $upload_ext, - "upload_name" => $upload_name, - "upload_file" => $upload_file, - "upload_url" => $upload_url, - "upload_source_name" => $upload_source_name, - "upload_size" => filesize($upload_file), - "upload_error" => "" - ); - } else { - $response['files'][$k] = array( - "upload_error" => "File write error." - ); - } - } else { - $response['files'][$k] = array( - "upload_error" => "Not allowed file type." - ); - } - } + // make file data + $response['files'][$k] = array( + "storage_type" => $storage_type, + "upload_ext" => $upload_ext, + "upload_name" => $upload_name, + "upload_file" => $upload_file, + "upload_url" => $upload_url, + "upload_source_name" => $upload_source_name, + "upload_size" => filesize($upload_file), + "upload_error" => "" + ); + } else { + $response['files'][$k] = array( + "upload_error" => "File write error." + ); + } + } else { + $response['files'][$k] = array( + "upload_error" => "Not allowed file type." + ); + } + } - return $response['files']; - } + return $response['files']; + } } if(!check_function_exists("read_storage_file")) { @@ -262,9 +263,9 @@ if(!check_function_exists("write_storage_file")) { $result = false; $filename = get_value_in_array("filename", $options, make_random_id(32)); - if(!array_key_empty("extension", $options)) { + if(!array_key_empty("extension", $options)) { $filename = sprintf("%s.%s", $filename, $options['extension']); - } + } $storage_type = get_value_in_array("storage_type", $options, "data"); $mode = get_value_in_array("mode", $options, "w");