时间:2021-07-01 10:21:17 帮助过:59人阅读
下面是完整的PHP上传图片代码;
- <formenctypeformenctype="multipart/form-data"action=""method="post">
- <inputtypeinputtype="hidden"name="max_file_size"value="200000">
- <inputnameinputname="userfile"type="file">
- <inputtypeinputtype="submit"name="submit"value="上传文件">
- form>
- php
- $type=array("jpg","gif","bmp","jpeg","png");
- $uploaddir="./file/";
- if(isset($_POST['submit']))
- {
- functiontexttype($name)
- {
- returnsubstr(strrchr($name,'.'),1);
- }
- if(!in_array(strtolower(texttype($_FILES['userfile']['name'])),$type))
- {
- $text=implode(",",$type);
- echo"您只能上传以下类型文件:",$text,"<br>";
- }
- else
- {
- if($_FILES['userfile']['size']<="200000")
- {
- $filename=explode(".",$_FILES['userfile']['name']);
- $time=date("m-d-H-i-s");
- $filename[0]=$time;
- $name=implode(".",$filename);
- $uploadfile=$uploaddir.$name;
- if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile))
- {
- echo"<center>您的文件已经上传完毕上传图片预览:center><br><center><imgsrcimgsrc='$uploadfile'>center>";
- echo"<br><center><ahrefahref='javascrīpt:history.go(-1)'>继续上传a>center>";
- }
- else
- {
- echo"传输失败!";
- }
- }
- else
- {
- echo"图片太大";
- }
- }
- }
- ?>
以上就是详细的PHP上传图片代码,希望对大家有帮助。
http://www.bkjia.com/PHPjc/446552.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446552.htmlTechArticle学习PHP时,你可能会遇到PHP上传图片问题,这里将介绍详细的PHP上传图片代码解决这个问题,在这里拿出来和大家分享一下。php的语法非常...