fix: image upload limit and path resolution between publik and kemiskinan

This commit is contained in:
2026-06-12 10:43:05 +07:00
parent 0d995aee1e
commit b81a0166fa
5 changed files with 55 additions and 25 deletions
+16 -7
View File
@@ -33,18 +33,27 @@ 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);
}
$dest_path = $upload_file_dir . $new_file_name;
if (move_uploaded_file($file_tmp_path, $dest_path)) {
if (@move_uploaded_file($file_tmp_path, $dest_path)) {
return $new_file_name;
}
}