Update storage.php
This commit is contained in:
parent
0ed4a5f425
commit
629ef90722
|
@ -2,6 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* @file storage.php
|
* @file storage.php
|
||||||
* @date 2018-05-27
|
* @date 2018-05-27
|
||||||
|
* @updated 2019-10-13
|
||||||
* @author Go Namhyeon <gnh1201@gmail.com>
|
* @author Go Namhyeon <gnh1201@gmail.com>
|
||||||
* @brief Stroage module for ReasonableFramework
|
* @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")) {
|
if(!check_function_exists("move_uploaded_file_to_storage")) {
|
||||||
function move_uploaded_file_to_stroage($options=array()) {
|
function move_uploaded_file_to_stroage($options=array()) {
|
||||||
$response = array(
|
$response = array(
|
||||||
"files" => array()
|
"files" => array()
|
||||||
);
|
);
|
||||||
|
|
||||||
$requests = get_requests();
|
$requests = get_requests();
|
||||||
$files = $requests['_FILES'];
|
$files = $requests['_FILES'];
|
||||||
|
|
||||||
$storage_type = get_value_in_array("storage_type", $options, "data");
|
$storage_type = get_value_in_array("storage_type", $options, "data");
|
||||||
$upload_base_path = get_storage_path($storage_type);
|
$upload_base_path = get_storage_path($storage_type);
|
||||||
$upload_base_url = get_storage_url($storage_type);
|
$upload_base_url = get_storage_url($storage_type);
|
||||||
|
|
||||||
if(!array_key_empty("only_image", $options)) {
|
if(!array_key_empty("only_image", $options)) {
|
||||||
$upload_allow_ext = array(
|
$upload_allow_ext = array(
|
||||||
"png", "gif", "jpg", "jpeg", "tif"
|
"png", "gif", "jpg", "jpeg", "tif"
|
||||||
);
|
);
|
||||||
} elseif(!array_key_empty("only_docs", $options)) {
|
} elseif(!array_key_empty("only_docs", $options)) {
|
||||||
$upload_allow_ext = array(
|
$upload_allow_ext = array(
|
||||||
"png", "gif", "jpg", "jpeg", "tif",
|
"png", "gif", "jpg", "jpeg", "tif",
|
||||||
"xls", "ppt", "doc", "xlsx", "pptx",
|
"xls", "ppt", "doc", "xlsx", "pptx",
|
||||||
"docx", "odt", "odp", "ods", "xlsm",
|
"docx", "odt", "odp", "ods", "xlsm",
|
||||||
"tiff", "pdf", "xlsm"
|
"tiff", "pdf", "xlsm"
|
||||||
);
|
);
|
||||||
} elseif(!array_key_empty("only_audio", $options)) {
|
} elseif(!array_key_empty("only_audio", $options)) {
|
||||||
$upload_allow_ext = array(
|
$upload_allow_ext = array(
|
||||||
"mp3", "ogg", "m4a", "wma", "wav"
|
"mp3", "ogg", "m4a", "wma", "wav"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$upload_allow_ext = array();
|
$upload_allow_ext = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($files as $k=>$file) {
|
foreach($files as $k=>$file) {
|
||||||
$upload_ext = get_file_extension($files[$k]['name']);
|
$upload_ext = get_file_extension($files[$k]['name']);
|
||||||
$upload_name = make_random_id(32) . (empty($upload_ext) ? "" : "." . $upload_ext);
|
$upload_name = make_random_id(32) . (empty($upload_ext) ? "" : "." . $upload_ext);
|
||||||
$upload_file = $upload_base_path . "/" . $upload_name;
|
$upload_file = $upload_base_path . "/" . $upload_name;
|
||||||
$upload_url = $upload_base_url . "/" . $upload_name;
|
$upload_url = $upload_base_url . "/" . $upload_name;
|
||||||
|
|
||||||
if(count($upload_allow_ext) == 0 || in_array($upload_ext, $upload_allow_ext)) {
|
if(count($upload_allow_ext) == 0 || in_array($upload_ext, $upload_allow_ext)) {
|
||||||
if(move_uploaded_file($files[$k]['tmp_name'], $upload_file)) {
|
if(move_uploaded_file($files[$k]['tmp_name'], $upload_file)) {
|
||||||
// get file source name
|
// get file source name
|
||||||
$upload_source_name = $files[$k]['name'];
|
$upload_source_name = $files[$k]['name'];
|
||||||
if(strlen($upload_source_name) == 0) {
|
if(strlen($upload_source_name) == 0) {
|
||||||
$upload_source_name = $upload_name;
|
$upload_source_name = $upload_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make file data
|
// make file data
|
||||||
$response['files'][$k] = array(
|
$response['files'][$k] = array(
|
||||||
"storage_type" => $storage_type,
|
"storage_type" => $storage_type,
|
||||||
"upload_ext" => $upload_ext,
|
"upload_ext" => $upload_ext,
|
||||||
"upload_name" => $upload_name,
|
"upload_name" => $upload_name,
|
||||||
"upload_file" => $upload_file,
|
"upload_file" => $upload_file,
|
||||||
"upload_url" => $upload_url,
|
"upload_url" => $upload_url,
|
||||||
"upload_source_name" => $upload_source_name,
|
"upload_source_name" => $upload_source_name,
|
||||||
"upload_size" => filesize($upload_file),
|
"upload_size" => filesize($upload_file),
|
||||||
"upload_error" => ""
|
"upload_error" => ""
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$response['files'][$k] = array(
|
$response['files'][$k] = array(
|
||||||
"upload_error" => "File write error."
|
"upload_error" => "File write error."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$response['files'][$k] = array(
|
$response['files'][$k] = array(
|
||||||
"upload_error" => "Not allowed file type."
|
"upload_error" => "Not allowed file type."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response['files'];
|
return $response['files'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!check_function_exists("read_storage_file")) {
|
if(!check_function_exists("read_storage_file")) {
|
||||||
|
@ -262,9 +263,9 @@ if(!check_function_exists("write_storage_file")) {
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
||||||
$filename = get_value_in_array("filename", $options, make_random_id(32));
|
$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']);
|
$filename = sprintf("%s.%s", $filename, $options['extension']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$storage_type = get_value_in_array("storage_type", $options, "data");
|
$storage_type = get_value_in_array("storage_type", $options, "data");
|
||||||
$mode = get_value_in_array("mode", $options, "w");
|
$mode = get_value_in_array("mode", $options, "w");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user