2013-02-07 15 views
5

मुझे थंबनेल छवियों क्लाइंट साइड बनाने और अपलोड करने पर यह धागा मिला है। ट्रेड दिखाता है कि पहली छवि को कैसे अपलोड करें, फिर इसे आकार देने और फिर से अपलोड करके फ़ॉलो करें। अगर वहाँ एक आसान तरीका एक और कदम जोड़ने के लिए तो अंतिम परिणाम का उत्पादन होता है और है मैं सोच रहा था मूल, मध्यम आकार और थंबनेलप्लुपलोड एकाधिक आकार के थंबनेल बनाएं

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. 

चेतावनी # 1: आप पूर्ण आकार छवि के बाद थंबनेल अपलोड करना चाहिए अन्यथा, पूर्ण आकार की छवि में कुछ बफर मुद्दे हो सकते हैं और कट ऑफ हो सकते हैं।

चेतावनी # 2: यह केवल तभी काम करेगा जब FileUploaded के लिए बाइंड कॉल uploader.init() के बाद होता है, अन्यथा अपलोडर के स्वयं के हैंडलर FileUploaded के लिए फ़ाइल को ओवरराइट कर देगा। आपके हैंडलर के बाद वापस जाएँ। नीचे

इस सूत्र से मूल प्रतिक्रिया 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(); 
    } 
} 

उत्तर

7

काफी सरल है, मैं अपने प्रोजेक्ट में ऐसा ही किया, दो मामूली समायोजन के साथ है।

upload.php मैं गतिशील निर्देशिका जानकारी बनाया में:

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

और अपलोड इंटरफ़ेस में कोड बदल दिया है:

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

जवाब Eduardo de Souza द्वारा दिए गए मेरे लिए बहुत उपयोगी है, लेकिन यहां इस कोड को काम करने के लिए कुछ बदलाव मध्यम फ़ाइल अपलोड नहीं कर सकते हैं और दूसरी छवि को आकार बदलने के रूप में आकार नहीं बदला जा सकता है क्योंकि मुझे अपने मामले में कुछ बदलाव मिले हैं:

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(); 
         } 
        } 
       }); 
      }); 

आकार परम जो छवि आकार और भी मध्यम यूआरएल पर नोटिस geting के लिए i चर के साथ कुछ जाँच कर में एक attribue enabled:true जोड़ लिया है, मैं इस उपयोगी हो सकता है लगता है।

संबंधित मुद्दे