/PHP 实现文件的上传
<?php
$allowedExts=array('gif','jpeg','jpg','png');
$temp=explode(".", $_FILES['file']['name']);
$extension=end($temp);//获得文件的后缀名
if((($_FILES['file']['type']=='image/gif')
||($_FILES['file']['type']=='image/jpeg')
||($_FILES['file']['type']=='image/jpg')
||($_FILES['file']['type']=='image/pjpeg')
||($_FILES['file']['type']=='image/x-png')
||($_FILES['file']['type']=='image/png'))
&&($_FILES['file']['size']<204800) //小于200kb
&&in_array($extension, $allowedExts))
{
if ($_FILES['file']['error']>0)
echo "错误:".$_FILES['file']['error']."<br/>";
else
{
echo "上传的文件名:".$_FILES['file']['name']."<br/>";
echo "文件类型:".$_FILES['file']['type']."<br/>";
echo "文件大小:".($_FILES['file']['size']/1024)."kb"."<br/>";
echo "文件临时存储位置:".$_FILES['file']['tmp_name'];
//判断当前目录下面Upload 目录是否存在该文件
//如果没有Upload 目录,你需要创建它,upload目录的权限为777
if(file_exists("./upload/".$_FILES['file']['name']))
{
echo $_FILES['file']['name']."文件已经存在"."<br/>";
}
else
{
move_uploaded_file($_FILES['file']['tmp_name'], "./upload/".$_FILES['file']['name']);
echo "文件存储在:"."./upload/".$_FILES['file']['name']."<br/>";
}
}
}
else
{
echo "文件格式不正确!";
}