標籤:class end Enctype 過濾 example sheet 檔案 控制器 func
模板檔案: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="/Public/jquery.uploadify-v2.1.0/example/css/default.css" rel="stylesheet" type="text/css" /><link href="/Public/jquery.uploadify-v2.1.0/uploadify.css" rel="stylesheet" type="text/css" /><script charset="utf-8" type="text/javascript" src="/Public/jquery.uploadify-v2.1.0/jquery-1.3.2.min.js"></script><script charset="utf-8" type="text/javascript" src="/Public/jquery.uploadify-v2.1.0/swfobject.js"></script><script charset="utf-8" type="text/javascript" src="/Public/jquery.uploadify-v2.1.0/jquery.uploadify.v2.1.0.min.js"></script><style type="text/css">#image{ height:300px; width:720px; border:1px #969594 solid;}</style><title>圖片上傳</title></head><body><form id="form1" enctype="multipart/form-data" > <div id="fileQueue" style=‘height:200px;display:none‘></div> <input type="file" name="uploadify" id="uploadify" multiple="true" /> </div></form><div id="image" ></div><script type="text/javascript">$(document).ready(function () { $("#uploadify").uploadify({ ‘uploader‘:‘/Public/jquery.uploadify-v2.1.0/uploadify.swf‘, //swf路徑 ‘script‘: ‘/Code/file‘, //幕後處理檔案上傳的路徑 ‘cancelImg‘:‘/Public/jquery.uploadify-v2.1.0/cancel.png‘, //按鈕背景圖片的路徑 ‘folder‘: ‘/Uploads‘, ‘method‘:‘post‘, ‘buttonText‘:‘file‘, ‘fileExt‘: ‘*.jpg;*.gif,*.png‘, //允許上傳的檔案格式為*.jpg,*.gif,*.png ‘fileDesc‘: ‘Web Image Files(.JPG,.GIF,.PNG)‘, //過濾掉除了*.jpg,*.gif,*.png的檔案 ‘queueID‘: ‘fileQueue‘, ‘sizeLimit‘: ‘2048000‘, //最大允許的檔案大小為2M ‘fileDataName‘:‘uploadify‘, ‘auto‘: false, ‘queueSizeLimit‘:15, ‘simUploadLimit‘:15, ‘removeCompleted‘:false, ‘multi‘:true, ‘onCancel‘: funCancel, //當使用者取消上傳時 ‘onComplete‘: funComplete, //完成上傳任務 ‘OnError‘: funError //上傳發生錯誤時 });});//使用者取消函數function funCancel(event, ID, fileObj, data) { alert(‘您取消了操作‘); return;}//圖片上傳發生的事件function funComplete(event, ID, fileObj, response, data) { //alert(‘上傳事件‘); if (response == 0) { alert(‘圖片‘ + fileObj.name + ‘操作失敗‘); return false; }else{ var str=$(‘#image‘).html(); var add="<img src=‘"+"/Uploads/"+response+"‘" +"style=‘margin-left:15px;margin-top:15px‘/></img>"; str+=add; $(‘#image‘).html(str); return true; }}//上傳發生錯誤時。function funError(event, ID, fileObj, errorObj) { //alert(‘錯誤事件‘); alert(errorObj.info); return;}</script> <a href="javascript:$(‘#uploadify‘).uploadifyUpload()">上傳</a>| </body></html>控制器類:<?php/* * 新聞類 */class ArticleAction extends Action{ // /*public function load() { import(‘@.ORG.editor‘); $ob=new editor("800px",‘400px‘,‘editor‘); $str=$ob->userJs(); $editor=$ob->createEditor(); $this->assign("str",$str); $this->assign("editor",$editor); $this->display(); } // public function php() { import(‘@.ORG.editor‘); $ob=new editor( ); $content=$ob->getEditorContent(); $this->assign(‘content‘,$content); $this->display(); } */ public function file() { //負載檔案上傳,圖片處理類 import("@.ORG.UploadFile"); //匯入上傳類 $upload = new UploadFile(); //設定上傳檔案大小 $upload->maxSize=3292200; //設定上傳檔案類型 $upload->allowExts=explode(‘,‘,‘jpg,gif,png,jpeg‘); //設定附件上傳目錄 $upload->savePath=‘./Uploads/‘; //設定需要產生縮圖,僅對影像檔有效 $upload->thumb = true; // 設定引用圖片類庫包路徑 $upload->imageClassPath =‘@.ORG.Image‘; //設定需要產生縮圖的檔案尾碼 $upload->thumbPrefix=‘m_,s_‘; //生產2張縮圖 //設定縮圖最大寬度 $upload->thumbMaxWidth=‘400,100‘; //設定縮圖最大高度 $upload->thumbMaxHeight=‘400,100‘; //設定上傳檔案規則 $upload->saveRule=‘uniqid‘; //刪除原圖 $upload->thumbRemoveOrigin=true; if( !$upload->upload() ) { echo ‘0‘; }else{ $info=$upload->getUploadFileInfo(); $src=‘s_‘.$info[0][‘savename‘]; echo $src; } } public function preview () { $this->display(); } }
php thinkphp uploadify