2011-04-14 65 views
1

我目前編碼的網站的一部分,允許用戶上傳圖像,然後選擇該圖像的區域進行裁剪。我想要它,以便該圖像上傳時用戶不必提交表單,所以我使用一個名爲swfupload的工具,我設法獲取圖像上傳,但是我無法獲得swfupload來創建縮略圖,甚至無法讀取我的縮略圖方法。codeigniter圖像上傳和調整大小 - swfupload

下面是我的代碼,

PHP

public function upload() 
    { 
     $config['upload_path'] = "./media/uploads/users"; 
     $config['allowed_types'] = 'gif|jpg|png'; 
     $config['max_size'] = '1000'; 
     $config['max_width'] = '1024'; 
     $config['max_height'] = '768'; 
     $config['encrypt_name'] = TRUE; 

     $this->load->library('upload', $config); 


     if (! $this->upload->do_upload('Filedata')) 
     { 
      $error = array('error' => $this->upload->display_errors()); 
      //die(print_r($error)); 
     } 
     else 
     { 
      $this->file = $this->upload->data(); 
      echo $this->file['file_name']; 
     } 
    } 

    public function thumbnail() 
    { 
       //lets just try and get thumbnail() talking to swfupload 
     echo 1; 
    } 

SWFUpload的JS

window.onload = function() { 
      swfu = new SWFUpload({ 
       // Backend Settings 
       upload_url: "http://lcl.moovjob.com/index.php/admin/users/upload", 
       post_params: {"PHPSESSID": "<?php echo $this->session->userdata('session_id'); ?>" }, 

       // File Upload Settings 
       file_size_limit : "5 MB", // 5MB 
       file_types : "*.jpg", 
       file_types_description : "JPG Images", 
       file_upload_limit : "0", 

       // Event Handler Settings - these functions as defined in Handlers.js 
       // The handlers are not part of SWFUpload but are part of my website and control how 
       // my website reacts to the SWFUpload events. 
       file_queue_error_handler : fileQueueError, 
       file_dialog_complete_handler : fileDialogComplete, 
       upload_progress_handler : uploadProgress, 
       upload_error_handler : uploadError, 
       upload_success_handler : uploadSuccess, 
       upload_complete_handler : uploadComplete, 

       // Button Settings 
       button_image_url : "images/SmallSpyGlassWithTransperancy_17x18.png", 
       button_placeholder_id : "spanButtonPlaceholder", 
       button_width: 180, 
       button_height: 18, 
       button_text : '<span class="button">Select Images <span class="buttonSmall">(2 MB Max)</span></span>', 
       button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }', 
       button_text_top_padding: 0, 
       button_text_left_padding: 18, 
       button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT, 
       button_cursor: SWFUpload.CURSOR.HAND, 

       // Flash Settings 
       flash_url : "/media/flash/swfupload.swf", 

       custom_settings : { 
        upload_target : "divFileProgressContainer" 
       }, 

       // Debug Settings 
       debug: true 
      }); 
     }; 

我的處理程序JS,尤其是上傳成功的方法,

function uploadSuccess(file, serverData) { 
    try { 
     var progress = new FileProgress(file, this.customSettings.upload_target); 

     if (serverData.substring(0, 7) === "FILEID:") { 
      addImage("http://local.test.com/index.php/admin/users/thumbnail"); 

      progress.setStatus("Thumbnail Created."); 
      progress.toggleCancel(false); 
     } else { 
      addImage("images/error.gif"); 
      progress.setStatus("Error."); 
      progress.toggleCancel(false); 
      alert(serverData); 

     } 


    } catch (ex) { 
     this.debug(ex); 
    } 
} 

什麼時我爲此而做所有我想要的圖像都是上傳的,然後返回1,所以我知道swfupload正在與我的控制器通話。我回來的是上傳成功或錯誤。

回答

0

我有點困惑爲什麼你不把縮略圖方法添加到你的上傳功能的結尾?就我所能想到的而言,不需要單獨進行這些操作。

您已經在上傳功能中檢查成功上傳,因此在它返回任何數據之前,請將文件名/目錄傳遞給您的縮略圖函數,創建縮略圖,然後以此方式將成功或失敗返回給您的js。