1、在default中的Index文件夾中新建一個(gè)index.html模板,代碼如下:
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title> New Document </title>
- <meta name="Generator" content="EditPlus">
- <meta name="Author" content="">
- <meta name="Keywords" content="">
- <meta name="Description" content="">
- </head>
- <body>
- <form METHOD=POST action="__URL__/upload" enctype="multipart/form-data" >
- <input type="text" NAME="name" >
- <input type="text" NAME="email" >
- <input type="file" name="photo" >
- <input type="submit" value="保 存" >
- </form>
- </body>
- </html>
2、在控制器的IndexAction.class.php中執(zhí)行下面代碼
- <?php
- // 本文檔自動(dòng)生成,僅供測(cè)試運(yùn)行
- class IndexAction extends Action
- {
- public function index()
- {
- $this->display();
- }
- public function upload(){
- if(!emptyempty($_FILES)){
- $this->_upload();
- }
- }
- public function _upload(){
- import("ORG.Net.UploadFile");
- $upload = new UploadFile();
- //設(shè)置上傳文件大小
- $upload->maxsize = 3145728;
- //設(shè)置上傳文件類型
- $upload->allowExts = explode(',',"jpg,gif,jpeg,png");
- //設(shè)置附近上傳目錄
- $upload->savePath = "./Tpl/default/Public/image/"; //注意 目錄為入口文件的相對(duì)路徑
- //設(shè)置需要生成縮略圖他,僅對(duì)圖片文件有效
- //$upload->thumb = true;
- //設(shè)置引用圖片類庫(kù)包路徑
- //$upload->imageClassPath = 'ORG.Net.Image';
- //設(shè)置需要生成縮略圖他的文件后綴
- //$upload->thumbPrefix ='m_,s_'; //生成2張縮略圖
- //設(shè)置縮略圖最大寬度
- //$upload->thumbMaxWidth = '400,100';
- //設(shè)置縮略圖最大高度
- //$upload->thumbMaxHeight = '400,100';
- //設(shè)置上傳文件規(guī)則
- $upload->saveRule = uniqid;
- //刪除原圖
- $upload->thumbRemoveOrigin = true;
- if(!$upload->upload()){
- //捕獲上傳異常
- $this->error($upload->getErrorMsg());
- }else{
- //取得成功上傳文件信息
- $info = $upload->getUploadFileInfo();
- $this -> success("上傳成功");
- }
- }
- }
- ?>
新聞熱點(diǎn)
疑難解答
圖片精選