Я пытался заставить мою функцию загрузки загружать листы Excel, но все, что я получаю, - недопустимый формат
Я пытался удалить оператор if, чтобы проверить формат файла, но все еще не могу загрузить что-либо еще, кроме 'jpg''jpeg' 'png' 'pdf'
очень странно, если попытаться загрузить документ / изображение в формате captizaled, таком как JPG или PDF, будет отображаться та же ошибка: «Ошибка: выберите правильный формат файла».
<?php
// Check if the form was submitted
date_default_timezone_set("Asia/Bahrain");
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Check if file was uploaded without errors
// if(isset($_FILES["file"]) || !isset($_POST['RRidupload']) && $_FILES["photo"]["error"] == 0 )
if(isset($_FILES["file"])){
echo "<pre>";
//$allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "gif" => "image/gif", "png" => "image/png", "pdf" => "application/pdf", "pdf" => "application/pdf");
$allowed = array('jpg', 'jpeg','png','pdf','PDF','JPG','xlsx','xls');
foreach($_FILES["file"]["name"] as $key=>$val){
$filename = $_FILES["file"]["name"][$key];
$filetype = $_FILES["file"]["type"][$key];
$filesize = $_FILES["file"]["size"][$key];
// Verify file extension
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!array_key_exists($ext, $allowed)) die("Error: Please select a valid file format.");
// Verify file size - 5MB maximum
$maxsize = 5 * 1024 * 1024;
if($filesize > $maxsize) die("Error: File size is larger than the allowed limit.");
$RR_id = $_POST['RRidupload']; // required
if (!file_exists('upload/'. $RR_id)) {
mkdir('upload/'. $RR_id, 0777, true);
}
// Verify MYME type of the file
if(in_array($filetype, $allowed)){
// Check whether file exists before uploading it
if(file_exists("upload/". $RR_id . "/" . $filename)){
echo $filename . " is already exists.";
} else{
move_uploaded_file($_FILES["file"]["tmp_name"][$key], "upload/". $RR_id . "/" . $filename);
echo "Your file was uploaded successfully.";
}
} else{
echo "Error: There was a problem uploading your file. Please try again.";
}
}
} else{
echo "Error: " . $_FILES["file"]["error"];
}
}
?>