Home > Backend Development > PHP Tutorial > thinkphp中怎么办上传文件

thinkphp中怎么办上传文件

WBOY
Release: 2016-06-13 10:05:46
Original
753 people have browsed it

thinkphp中怎么处理上传文件
thinkphp中怎么处理上传文件,也即要处理所有文件。自己做了一个网站要上传所有的文件 包括图片、txt、doc、视频等等。如何上传 插入数据库里面呀?
$m = M("file");
//$_clean = array();
if (!empty($_FILES)){
  $im = $this->_upload();
  $_POST["filename"] = $im;
  $_POST["uptime"] = time();
 
  }

$n = $m->add();
if ($n){
  $str = "添加成功";
  }else {
  $str = "添加失败";
  }
  $this->assign("str",$str);
  $this->display("upload");
}

// 文件上传 
  protected function _upload() { 
  import("@.ORG.UploadFile"); 
  $upload = new UploadFile(); 
  //设置上传文件大小 
  $upload->maxSize = 3292200; 
  //设置上传文件类型 
  $upload->allowExts = explode(',', 'jpg,gif,png,jpeg,pjpeg,bmp,doc,rar,txt'); 
  //设置附件上传目录 
  $upload->savePath = './Public/upload/'; 
  //设置上传文件规则 
  $upload->saveRule = uniqid;
  if (!$upload->upload()) { 
  //捕获上传异常 
  $this->error($upload->getErrorMsg()); 
  } else { 
  //取得成功上传的文件信息 
  $uploadList = $upload->getUploadFileInfo(); 
  //import("@.ORG.Image"); 
  //给m_缩略图添加水印, Image::water('原文件名','水印图片地址') 
  /*Image::water($uploadList[0]['savepath'].'m_'.$uploadList[0]['savename'], '/ThinkPHP_2.1_full_with_extend/Examples/File/Tpl/default/Public/Images/logo2.png'); */
  return $uploadList[0]['savename']; 
  } 
   
} 我这样处理不行哦。

------解决方案--------------------
http://thinkphp.cn/Manual/170
------解决方案--------------------
thinkphp不是有demo吗?
------解决方案--------------------
$upload->savePath = './Public/upload/';
改成
$upload->savePath = './upload/';
你试一试

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template