0

我正在制作一个上传脚本,并且我已经进行了编码,因此除了图像之外的任何文件都不会被上传,但该脚本也在上传其他文件,而且当我回显扩展名时,它只显示 $name 的 strpos。有人可以帮忙吗???我保存了两个文件,1) uploader.php 和 2) uploader2.php。uploader.php 包含上传脚本的形式

    <h1>Upload your pictures for free</h1>
<form action="uploader2.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploads">
<input type="submit" value="Update">

uploader2.php 包含上传脚本到文件夹 uploads/

<?php
error_reporting(E_ALL ^ E_NOTICE);
$name = $_FILES['uploads']['name'];
echo $type= $_FILES['uploads']['type'];
$extension = strtolower($name,strpos($name,'.')+1));
$size = $_FILES['uploads']['size'];

$max_size = "20000000";
$t_n = $_FILES['uploads']['tmp_name'];

if(isset($name)) {
if(!empty($name)) {

if(($extension=="jpg" || $extension=="jpeg" || $extension=="bmp" || $extension=="gif")                            && ($type="image/jpeg" || $type="image/bmp")&&($size<=$max_size)){

$location="uploads/";

if(move_uploaded_file($t_n,$location.$name)){
echo "Uploaded!";
}else{
echo "An error occured";
}
}
else{
echo "The uploading file must be jpg or jpeg and should have size less than 1mb";
}
}

else {
echo "Please choose a file";
}
}

?>
4

1 回答 1

0

您可以使用它来获取扩展名

$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
于 2013-11-11T13:02:30.283 回答