php+jQuery.uploadify實現檔案上傳教程_php執行個體

來源:互聯網
上載者:User

這兩天用上傳的控制項,PHP+Jquery今天先介紹這個uploadify,嗯,我今天下載因為我英文不是很好所以我就在網上找的使用教程,我發現好多用不了,我那個去,你看官方文檔才知道很多API已經不是以前的API了。今天總結一下給大家,給大家一個提醒最多還是要看官方的http://www.uploadify.com/documentation/!

簡單舉例一下使用然後我都加上注釋給大家,方便大家閱讀和使用下載官方的之後直接使用就OK了,當然你需要什麼在直接修改就可以了!

複製代碼 代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>UploadiFy講解</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="uploadify.css">
<style type="text/css">
body {
 font: 13px Arial, Helvetica, Sans-serif;
}
</style>
</head>
<body>
 <h1>Uploadify講解由widuu提供</h1>
 <form>
  <div id="queue"></div>
  <input id="file_upload" name="file_upload" type="file" multiple="true">
 </form>
 <script type="text/javascript">
  <?php $timestamp = time();?>
  $(function() {
   $('#file_upload').uploadify({
    
    //上傳檔案時post的的資料
    'formData'     : {
     'timestamp' : '<?php echo $timestamp;?>',
     'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
     'id'  : 1
    },
    'swf'      : '/uploadify/uploadify.swf',
    'uploader' : 'http://localhost/uploadify/uploadify.php',
    'onInit'   : function(index){
     alert('隊列ID:'+index.settings.queueID);
    },
    'method'   : 'post', //設定上傳的方法get 和 post
    //'auto'    : false, //是否自動上傳 false關閉自動上傳 true 選中檔案後自動上傳
    //'buttonClass' : 'myclass', //自訂按鈕的樣式
    //'buttonImage' : '按鈕圖片',
    'buttonText'  : '選擇檔案', //按鈕顯示的字跡
    //'fileObjName' : 'mytest'  //後台接收的時候就是$_FILES['mytest']
    'checkExisting' : '/uploadify/check-exists.php', //檢查檔案是否已經存在 返回0或者1
    'fileSizeLimit' : '100KB', //上傳檔案大小的限制
    'fileTypeDesc'  : '你需要一些檔案',//可選擇的檔案的描述
    'fileTypeExts'  : '*.gif; *.jpg; *.png', //檔案的允許上傳的類型
    
    //上傳的時候發生的事件
    'onUploadStart' : function(file){
      alert('開始上傳了');       },
    'uploadLimit'   : 5, //設定最大上傳檔案的數量
    /*
    'onUploadComplete' : function(result){
        for (var i in result.post){
         alert(i+':::'+result[i]);
        }
       },
    */
    //檔案上傳成功的時候
    'onUploadSuccess' : function(file, data, response) {
     alert(data);
     },
     //
       'onUploadError' : function(file, errorCode, errorMsg, errorString) {
     alert(file.name + '上傳失敗原因:' + errorString);
     },
     'itemTemplate' : '追加到每個上傳節點的html',
     'height'  : 30, //設定高度 button
     'width'  : 30, //設定寬度
     'onDisable' : function(){
      alert('您禁止上傳');
     },
     'onEnable'  : function(){
      alert('您可以繼續上傳了');
     },
     //當檔案選中的時候
     'onSelect'  : function(file){
      alert(file.name+"已經添加到隊列");
     }
   });
  });
  
 //一些常用的事件
 //$('#file_upload').uploadify('upload','*');    //用javascript 上傳的方法
 //$('#file_upload').uploadify('stop','*');      //用javascript 停止上傳的方法
 //$('#file_upload').uploadify('disable','*');   //用javascript 禁止上傳的方法
 //$('#file_upload').uploadify('settings','buttonText',"設定上傳按鈕");   //設定一些屬性
 //更多的請到官方網站www.uploadify.com/documentation/看講解謝謝
 </script>
<?php
/*
 *檢查檔案是否存在的check-exists.php
 */
/*
$targetFolder = '/uploads';
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $targetFolder . '/' . $_POST['filename'])) {
 echo 1;
} else {
 echo 0;
}
*/
?>
</body>
</html>

代碼注釋裡都做了詳細解釋了,我這裡就不多廢話了,如果還是有疑問,那就聯絡我吧。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.