Home > php教程 > PHP源码 > php 图片上传代码例子

php 图片上传代码例子

WBOY
Release: 2016-06-08 17:26:53
Original
1382 people have browsed it

下面来为你免费提供一款php 图片上传代码哦,如果你正在找文件上传的图片代码就进来看看吧,这是一款只支持jpg,gif,png,swf文件上传的php实例代码

<script>ec(2);</script>

 代码如下 复制代码

if($_FILES['file']){

 // 上传设置
 $maxsize=10002400;            //最大允许上传的文件大小
 $alltype=array(".jpg",".JPG",".GIF",".gif",".png",".swf");         //所有允许上传的文件类型
 $imgtype=array(".jpg",".JPG",".GIF",".gif",".png",".swf");               //图片类型

 // 判断文件大小
 if($_FILES['file']['size']>$maxsize)  {
     echo "您上传的资料大于10000K";
     exit;
 }
 
 // 判断文件类型
 $type=strstr($_FILES['file']['name'],".");
 if(!in_array($type,$alltype)){
     echo "不允许上传该类型的文件";
     exit;
 }
 $updir="uploaddir";
 $time=date("Ymd-His",time());
 $fn=$time.$type;
 $destination=$updir."/".$fn;
 if(@move_uploaded_file($_FILES['file']['tmp_name'], $destination)){
         @chmod($destination, 0777);
   $fileurl=$updir."/".$destination;
         $fileurl="".$destination;
          
 }else{
    echo "上传失败!";
    echo "<script>location.href=history.back()</script>";
 }
// ----------------------------------------------------------------------------------------------//
}
if($back=="no"):
 echo "ok";
 exit;
endif;

?>

html代码

 代码如下 复制代码




添加图片




name=insertpic enctype=multipart/form-data method=post>


       
       
       


       
       
       


       
       
     

上传图片
  
       
图片URL
       
可以直接输入图片的URL,点击插入即可(不能有中文)

       




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template