PHP无法上载excel工作表或大写格式文件
我一直试图让我的上传功能上传excel表格,但我得到的是无效的格式 我尝试删除if语句以检查文件格式,但仍然无法上载除“jpg”“jpeg”“png”“pdf”以外的任何内容 wierdly如果尝试上载标题化格式(如JPG或PDF)的文档/图像,则会显示相同的错误:“错误:请选择有效的文件格式。”PHP无法上载excel工作表或大写格式文件,php,upload,Php,Upload,我一直试图让我的上传功能上传excel表格,但我得到的是无效的格式 我尝试删除if语句以检查文件格式,但仍然无法上载除“jpg”“jpeg”“png”“pdf”以外的任何内容 wierdly如果尝试上载标题化格式(如JPG或PDF)的文档/图像,则会显示相同的错误:“错误:请选择有效的文件格式。” <?php // Check if the form was submitted date_default_timezone_set("Asia/Bahrain"); if($_SERVE
<?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"];
}
}
?>