如何更正此文件上传脚本中的扩展规范?

时间:2013-11-11 12:57:00

标签: php file-upload

我正在制作一个上传脚本,我已编码,以便除了图像之外不会上传任何文件,但脚本也会上传其他文件,当我回显扩展时,它只显示$ 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包含上传文件到文件夹上传/

<?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";
}
}

?>

1 个答案:

答案 0 :(得分:0)

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

$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);