#uploadify的基本用法javascript
下載uploadify的插件壓縮包 連接(http://www.uploadify.com/demos/) 下載好了以後的就把解壓好的文件放到文件中,若是按模塊可放到公共Public下的static文件裏面。 ###第一步 引入和編寫HTML代碼php
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>UploadiFive Test</title> <link rel="stylesheet" href="__PUBLIC__/static/uploadify/uploadify.css" /> <script type="text/javascript" src="__STATIC__/jquery.min.js"></script> <script type="text/javascript" src="__PUBLIC__/static/uploadify/jquery.uploadify.min.js"></script> //引入css和js文件 <style type="text/css"> body { font: 13px Arial, Helvetica, Sans-serif; //設置body樣式 } </style> </head> <body> <form> <input id="file_upload" name="file_upload" type="file" multiple="true"> <div id="test"><img src="" alt=""></div> </form> </body> </html>
###第二步 javascript代碼css
<script type="text/javascript"> $(function() {$('#file_upload').uploadify( { "height" : 30,//設置瀏覽按鈕的高度 ,默認值:30, "width" : 120,//設置瀏覽按鈕的寬度 ,默認值:110 "swf" :"uploadify.swf",//[必須設置]swf的路徑 "fileObjName" : "download", "fileSizeLimit" : '200KB',//限制文件大小 "buttonText" : "上傳圖片",//瀏覽按鈕的文本,默認值:BROWSE "buttonClass" :"buttonClass", "uploader" : 'uploadify.php',//[必須設置]上傳文件觸發的url 'removeTimeout' : 1, 'fileTypeExts' : '*.jpg; *.png; *.gif;',//容許上傳的文件類型,限制彈出文件選擇框裏能選擇的文件 'onUploadSuccess':function(file, data, response){ console.log(file); var obj= $.parseJSON(data); console.log(obj); $('#test img').attr('src',obj.src); } }); }); </script>
###第三步uploadify.php代碼html
$targetFolder = '/uploads'; // Relative to the root $verifyToken = md5('unique_salt' . $_POST['timestamp']); $data=$_FILES['Filedata']['tmp_name']; move_uploaded_file($data,'./test/king.jpg'); $data=array( 'info'=>'上傳成功', 'src'=>'./test/king.jpg' ); echo json_encode($data);