现在的位置: 首页 > 综合 > 正文

php上传图片代码

2013年02月26日 ⁄ 综合 ⁄ 共 906字 ⁄ 字号 评论关闭
   
/**

    *功能:
     上传图片
    *参数说明:
    $imgpath:   FILE变量

    *返回值:
    1:$imgpath  上传图片成功后的完整图片路径

    2:false      上传图片失败
  2:false     上传图片失败失败
    *版本:
     v1.007年8月5日作第1次修改,
   */ 
 
  function upload_image($imgpath)
    {
      $name=$imgpath["name"];
      $tmp_name=$imgpath["tmp_name"];
   $type=$imgpath["type"];
      $size=$imgpath["size"];
      $uploadfile ="./static/images/upload_image/".time()."_".$imgpath['name'];
       
   $maxsize=500*1024;                                          //最大允许上许文件大小
   if($name=="")                                            //文件名为空
  {
   echo"<script>alert('请先选择要上传的图片文件!'); 
        window.history.back();</script>";
  }
      if($type!="image/pjpeg" && $type!="image/jpeg" &&$type!="image/gif")//文件类型不在指定范围
    {
   echo"<script>alert('上传文件只可以是JPEG或GIF类型的!');
   window.history.back();</script>";
    exit;
  }
      if($size>$maxsize)                                      //超过规定大小
  

抱歉!评论已关闭.