fix: image upload limit and path resolution between publik and kemiskinan
This commit is contained in:
@@ -36,13 +36,19 @@ 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/';
|
||||
if (!is_dir($upload_file_dir)) {
|
||||
|
||||
@@ -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/';
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,7 +572,7 @@ function renderPenduduk(item) {
|
||||
|
||||
let fotoHtml = '';
|
||||
if (item.foto_rumah) {
|
||||
fotoHtml += `<img src="uploads/${item.foto_rumah}" style="width:100%;height:120px;object-fit:cover;border-radius:8px;margin-bottom:8px;">`;
|
||||
fotoHtml += `<img src="../kemiskinan/uploads/${item.foto_rumah}" style="width:100%;height:120px;object-fit:cover;border-radius:8px;margin-bottom:8px;">`;
|
||||
}
|
||||
|
||||
const popup = `
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user