php实现图片的简单上传功能~
<?phpif($_SERVER['REQUEST_METHOD']=='POST'){ if (is_uploaded_file($_FILES['upfile']['tmp_name'])){ //判断文件是否上传 $upfile=($_FILES['upfile']); $name=$upfile['name']; $type=$upfile['type']; $size=$upfile['size']; $tmp_name=$upfile['tmp_name']; $error=$upfile['error']; //限制文件格式只可为:pjpeg png gif jpeg 格式! switch($type){ case 'image/pjpeg': $ok=1; break;case'image/png' : $ok=1; break;case 'image/gif' :$ok=1; break;case 'image/jpeg' :$ok=1; break; } if($ok && $error=='0'){ move_uploaded_file($tmp_name,'images/'.$name); echo "上传成功!";} else{ echo "非法文件!"; //非图片格式,给出提示 } }}unset($upfile,$error,$name,$ok,$size,$tmp_name,$type);?><!doctype><html> <head> <title>上传图片</title> </head> <body> <form action="" method="post" enctype="multipart/form-data" name="upform"> 上传文件:<input type="file" name="upfile"> <input type="submit" value="上传"><br> </form> </body></html> |
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦