2013-02-07 46 views
5

Tôi đã tìm thấy chuỗi này về cách tạo và tải lên hình ảnh thu nhỏ của phía máy khách. Tread cho thấy làm thế nào để tải lên hình ảnh đầu tiên sau đó theo dõi bằng cách thay đổi kích thước nó và tải lên một lần nữa. Tôi đã tự hỏi nếu có một cách dễ dàng để thêm bước khác để kết quả cuối cùng sẽ tạo và độc đáo, kích thước vừa và thumbnailPlupload Tạo nhiều hình thu nhỏ có kích thước

A better solution is to trigger QueueChanged in the FileUploaded handler, and then call refresh. This will initiate the upload again for the same file and you can set a property that you read in the BeforeUpload handler to adjust the file size. 

Cảnh báo # 1: bạn nên tải lên hình thu nhỏ sau khi hình ảnh kích thước đầy đủ, nếu không hình ảnh có kích thước đầy đủ có thể có một số vấn đề về bộ đệm và bị cắt.

Cảnh báo # 2: Điều này sẽ chỉ hoạt động nếu lệnh liên kết cho FileUploaded xảy ra sau khi uploader.init(), nếu không trình xử lý riêng của trình tải lên cho FileUploaded sẽ ghi đè tệp.status trở lại XONG sau khi bạn xử lý.

dưới đây là phản ứng ban đầu từ chủ đề này Plupload Thumbnail

uploader.bind('BeforeUpload', function(up, file) { 
    if('thumb' in file) 
     up.settings.resize = {width : 150, height : 150, quality : 100}; 
    else 
     up.settings.resize = {width : 1600, height : 1600, quality : 100}; 
} 

uploader.bind('FileUploaded', function(up, file) { 
    if(!('thumb' in file)) { 
     file.thumb = true; 
     file.loaded = 0; 
     file.percent = 0; 
     file.status = plupload.QUEUED; 
     up.trigger("QueueChanged"); 
     up.refresh(); 
    } 
} 

Trả lời

7

là khá đơn giản, tôi đã làm điều đó trong dự án của tôi, với hai điều chỉnh nhỏ.

Trong upload.php tôi đã thông tin thư mục tự động:

$diretorio = $_REQUEST["diretorio"]; 
$targetDir = 'upload/'.$diretorio; 

và thay đổi mã trong giao diện tải lên:

uploader.bind('BeforeUpload', function(up, file) { 
    if('thumb' in file){ 

     //thumb 
     up.settings.url = 'upload/upload.php?diretorio=thumbs', 
     up.settings.resize = {width : 100, height : 75, quality : 60}; 

     // medium size 
     up.settings.url = 'upload/upload.php?diretorio=medium', 
     up.settings.resize = {width : 200, height : 150, quality : 60}; 

    }else{ 
     up.settings.url = 'upload/upload.php?diretorio=full-size', 
     up.settings.resize = {quality : 100}; 
    }  
     uploader.bind('FileUploaded', function(up, file) { 
      if(!('thumb' in file)) { 
       file.thumb = true; 
       file.loaded = 0; 
       file.percent = 0; 
       file.status = plupload.QUEUED; 
       up.trigger("QueueChanged"); 
       up.refresh(); 
      } 
    });    
}); 
0

câu trả lời được đưa ra bởi Eduardo de Souza là rất hữu ích đối với tôi nhưng có một số thay đổi để làm việc mã này ở đây không thể tải lên tập tin trung bình và khác là hình ảnh không thể thay đổi kích thước như thay đổi kích thước param cho tôi tìm thấy một số thay đổi trong trường hợp của tôi là:

var i = 1; 
uploader.bind('BeforeUpload', function (up, file) { 
       if ('thumb' in file) { 
        if (i == 1) { 
         //thumb 
         up.settings.url = 'http://localhost/plupload_new/public_html/upload.php?diretorio=thumb', 
           up.settings.resize = {width: 80, height: 80, enabled: true}; 
        } else { 
         // medium size 
         up.settings.url = 'http://localhost/plupload_new/public_html/upload.php?diretorio=medium', 
           up.settings.resize = {width: 800, height: 600, enabled: true}; 
        } 
       } else { 
        up.settings.url = 'http://localhost/plupload_new/public_html/upload.php?diretorio=full'; 
       } 
       uploader.bind('FileUploaded', function (up, file) { 
        if (!('thumb' in file)) { 
         file.thumb = true; 
         file.loaded = 0; 
         file.percent = 0; 
         file.status = plupload.QUEUED; 
         up.trigger("QueueChanged"); 
         up.refresh(); 
        } else { 
         if (i < 2) { 
          i++; 
          file.medium = true; 
          file.loaded = 0; 
          file.percent = 0; 
          file.status = plupload.QUEUED; 
          up.trigger("QueueChanged"); 
          up.refresh(); 
         } 
        } 
       }); 
      }); 

đã thêm một attribue enabled:true trong tham số thay đổi kích thước để thay đổi kích thước hình ảnh và một số kiểm tra với i biến để nhận thông báo trên url trung bình, tôi nghĩ điều này có thể hữu ích.

Các vấn đề liên quan