Update storage.php

This commit is contained in:
Namhyeon Go 2019-06-15 17:34:14 +09:00 committed by GitHub
parent c7b89a5ace
commit 548d5f643e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,67 +74,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_storage($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)) {
$response['files'][$k] = array( // get file source name
"storage_type" => $storage_type, $upload_source_name = $files[$k]['name'];
"upload_ext" => $upload_ext, if(strlen($upload_source_name) == 0) {
"upload_name" => $upload_name, $upload_source_name = $upload_name;
"upload_file" => $upload_file, }
"upload_url" => $upload_url,
"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']; // 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'];
}
} }
if(!check_function_exists("read_storage_file")) { if(!check_function_exists("read_storage_file")) {