我正在尝试上传excel文件,但它失败并显示错误:
“上传不成功”。我正在尝试两个不同的excel文件,但它显示了这个错误。我怎么能解决这个问题?
应该是什么问题?
这是代码:
require_once("connection.php");
if(isset($_POST['submit']))
{
$target_dir = "misc/";
$target_file = $target_dir . basename($_FILES["ex_file"]["name"]);
$uploadOk = 1;
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);
//echo $FileType;exit;
if (file_exists($target_file)) {
$_SESSION['message']="Sorry, file already exists. Rename the file , Try Again";
echo $_SESSION['message'];exit;
$uploadOk = 0;
}
// Check file size
if ($_FILES["ex_file"]["size"] > 5000000) {
$_SESSION['message']="Sorry, your file is too large.";
echo $_SESSION['message'];exit;
$uploadOk = 0;
}
// Allow certain file formats
if($FileType != "xls" && $FileType != "xlsx" ) {
$_SESSION['message']= "Sorry, only xls & xlsx files are allowed.";
echo $_SESSION['message'];exit;
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
$_SESSION['message']= "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["ex_file"]["tmp_name"], $target_file)) {
$_SESSION['message']="Upload Successfull";
// echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
$_SESSION['message']="Upload Unsuccessfull... Try Again";
//echo "Sorry, there was an error uploading your file.";
}
}
header('location:excel.php');
}
这里是html文件:
<form action="excel_upload.php" method="post" enctype="multipart/form-data" id="MyUploadForm">
<input name="type" value="excel" type="hidden" />
<input name="ex_file" id="ex_file" type="file" />
<input type="submit" name="submit" id="submit-btn" value="Upload" />
<img src="img/ajax-loader.gif" id="loading-img" style="display:none;" alt="Please Wait"/>
</form>
提前感谢。
是上传大小限制问题吗?