Plik nie jest przesyłany za pomocą modernizacji w Kotlin
define ('SITE_ROOT', realpath(dirname(__FILE__)));
//if(isset($_FILES['upload_file'])) {
$target_dir = "/uploads/";
$target_file = $target_dir . microtime().rand(99999,999999).basename($_FILES["upload_file"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["upload_file"]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
} else {
echo '{"status":"error","message":"فایل معتبر نیست"}';
$uploadOk = 0;
}
}
// Check file size
if ($_FILES["upload_file"]["size"] > 500000) {
echo '{"status":"error","message":"حجم عکس نباید بیشتر از 500 کیلوبایت باشد"}';
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
) {
echo '{"status":"error","message":"فرمت عکس اشتباه است"}';
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo '{"status":"error","message":"متاسفانه عکس آپلود نشد"}';
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["upload_file"]["tmp_name"], SITE_ROOT.$target_file)) {
echo '{"status":"success","message":"عکس با موفقیت آپلود شد"}';
} else {
echo '{"status":"error","message":"مشکل در آپلود فایل"}';
}
//}
}
Glamorous Gerenuk