thinkphp中怎麼辦上傳檔案

來源:互聯網
上載者:User
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/';
你試一試
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.