fix: image upload limit and path resolution between publik and kemiskinan
This commit is contained in:
@@ -36,15 +36,21 @@ function uploadFoto($file_input_name) {
|
||||
$file_tmp_path = $_FILES[$file_input_name]['tmp_name'];
|
||||
$file_name = $_FILES[$file_input_name]['name'];
|
||||
$file_size = $_FILES[$file_input_name]['size'];
|
||||
$file_type = mime_content_type($file_tmp_path);
|
||||
|
||||
$allowed_mime_types = ['image/jpeg', 'image/png', 'image/jpg'];
|
||||
$max_size = 2 * 1024 * 1024; // 2MB
|
||||
$file_type = 'unknown';
|
||||
if (function_exists('mime_content_type')) {
|
||||
$file_type = mime_content_type($file_tmp_path);
|
||||
} else {
|
||||
$file_type = $_FILES[$file_input_name]['type'];
|
||||
}
|
||||
|
||||
if (in_array($file_type, $allowed_mime_types) && $file_size <= $max_size) {
|
||||
$file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
|
||||
$allowed_mime_types = ['image/jpeg', 'image/png', 'image/jpg', 'image/webp'];
|
||||
$max_size = 10 * 1024 * 1024; // 10MB
|
||||
|
||||
if ($file_size <= $max_size) {
|
||||
$file_extension = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
|
||||
$new_file_name = uniqid($file_input_name . '_', true) . '.' . $file_extension;
|
||||
$upload_file_dir = '../uploads/';
|
||||
$upload_file_dir = '../../kemiskinan/uploads/';
|
||||
if (!is_dir($upload_file_dir)) {
|
||||
@mkdir($upload_file_dir, 0777, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user