标签:文件上传
html页面
<html> <head> </head> <body> <form action="8.php" method="post" enctype="multipart/form-data"> <input type="file" name="upfile"> <input type="submit" value="提交"> </form> </body> </html>
PHP上传页面
<?php $path=__DIR__.‘\\‘;//路径 $fileArray=array(‘image/jpeg‘,‘image/png‘);//允许上传的文件类型 $type=$_FILES["upfile"]["type"]; $tmp_name=$_FILES["upfile"]["tmp_name"]; $size=$_FILES["upfile"]["size"]; $name=$_FILES["upfile"]["name"]; if (!in_array($type, $fileArray)) { echo "<script>alert(‘只能上传JPG、PNG图片!!‘);history.back();</script>"; exit; } elseif ($size>2000000) { echo "<script>alert(‘上传图片不能超过2M!!‘);history.back();</script>"; exit; } else{ if (!is_uploaded_file($tmp_name)) { echo "<script>alert(‘上传临时文件失败!!‘);history.back();</script>"; } else{ if (!is_dir($path."uploads")) { mkdir($path.‘uploads‘); } if (!move_uploaded_file($tmp_name, $path.‘\\uploads\\‘.$name)) { echo "<script>alert(‘移动文件失败!!‘);history.back();</script>"; } else{ echo "<script>alert(‘上传成功!!‘);location.href=‘9.php?url=uploads/".$name."‘;</script>"; } } } ?>
PHP图片显示页面
<?php $path=__DIR__."\\uploads\\"; $file=$_GET[‘url‘]; echo "<img src=‘".$file."‘/>"; ?>
标签:文件上传
原文地址:http://sr0517.blog.51cto.com/809286/1846411