【发布时间】:2017-08-24 15:42:16
【问题描述】:
我在下面有一个示例代码,用于将图像作为用户输入,
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
但我的主要目的是这次上传Pdf & Docx 作为用户的输入而不是图片。
我试图改变,但没有成功。任何链接或至少包含几个链接的描述我可以假设其余的对我有用(我希望它是否是重复的,但不是以我猜的相同方式询问)。
【问题讨论】:
-
更改检查文件格式/etension的条件
-
@RavinderReddy 有很多东西要改变,你可以指定一些东西(例如将'$imageFileType'改为'$fileType')等等。我不了解语言本身,也找不到合适的术语或 API。
-
tx 哥们,我在它上面..
-
向我们展示错误或您尝试了什么
标签: php file-upload multifile-uploader