【发布时间】:2016-01-08 13:27:14
【问题描述】:
我的上传 php 代码可以允许所有文件类型,但我想阻止某些文件类型 这是我上传的php代码 我想屏蔽 .exe、.php 等文件类型
请简单说明一下我是php初学者
<?php
$target_dir = "/uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = filetype($_FILES["fileToUpload"]["tmp_name"]);
if($check !== true) {
echo "THANK YOU - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} 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.";
}
}
?>
【问题讨论】:
-
你能简单解释一下吗
标签: php