Home > php教程 > php手册 > PHP上传的方法(类)

PHP上传的方法(类)

WBOY
Release: 2016-06-13 10:36:52
Original
867 people have browsed it

一个很简单的,常用PHP上次方法,我是从类里给大家拿出来的,直接可以使用,也可以继续完善一下,bkJia视频教程里也详细讲解了PHP上传的方法,大家参考一下

/**
  * 图片上传方法-来源与bkJia中文网
  * $maxsize=500000 = 500k;
  * $updir="up/";
  * $upfile=$_FILES["file_img"];
  */
 public function Get_file_upload($upfile, $maxsize, $updir, $newname = date) {

  if ($newname == date)
   $newname = date("Ymdhs"); //使用日期做文件名
  $name = $upfile["name"];
  $type = $upfile["type"];
  $size = $upfile["size"];
  $tmp_name = $upfile["tmp_name"];

  switch ($type) {
   case image/pjpeg :
   case image/jpeg :
    $extend = ".jpg";
    break;
   case image/gif :
    $extend = ".gif";
    break;
   case image/png :
    $extend = ".png";
    break;
  }
  if (empty ($extend)) {
   echo 文件类型不正确,只能使用JPG GIF PNG 格式;  
  }
  if ($size > $maxsize) {
   $maxpr = $maxsize / 1000;
   echo "警告!上传图片大小不能超过";
  }
  if (move_uploaded_file($tmp_name, $updir . $newname . $extend)) {
   return $newname . $extend;
  }
 }

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