PHP上传图片代码!!

 特点:不同与其他网上PHP上传代码的是,这个可以上传多张图片,成功显示successful,失败显示fail,如果用户只想上传一张图片,不会显示fail!!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< title >无标题文档 </title>
</head>

< body >

<?
if(@$_POST['action1'])
{
set_time_limit(60);
for($i=1;$i<3;$i++)
{
echo " < br >";
$file="file";
$file=$file.$i;
@$file_tmp=$_FILES["$file"]["tmp_name"];

@$file_name=$_FILES["$file"]["name"];

$path="E:\EasyPHP1-8\www\upload\\";
$ext=end(explode(".",$file_name));
$file_new_name=time().".".$ext;
$filea=$path.$file_new_name;

if(copy($file_tmp,$filea))
    {
    echo "successful";

    echo " < br >";

    echo " < img src=\"upload\\$file_new_name\" >";
    }
    else
    {
    echo "fail!!";
    exit(1);
    }
    
}
}

else
{
?>

< form action ="90_1.php" method ="post" enctype ="multipart/form-data" >
< input type ="hidden" name ="MAX_FILE_SIZE" value ="800000" >
< input type ="hidden" name ="action1" value ="1" >
file1: < input type ="file" name ="file1" >
file2: < input type ="file" name ="file2" >
< input type ="submit" value ="上传" >
</form>

<?
}
?>
</body>
</html>

本文出自 “雷克地沟” 博客,请务必保留此出处http://240420643.blog.51cto.com/350567/101077

你可能感兴趣的:(PHP,职场,上传,休闲)