2010-10-31 9 views
5

üstbilgim kodu:jquery plugin 'uploadify' - Yükleme komut dosyasından bir yanıt vermek için yol?

$(document).ready(function() { 
    $('#sampleFile').uploadify({ 
     'uploader': 'include/uploadify/uploadify.swf', 
     'script': 'add_list.php', 
     'scriptData': {'mode': 'upload'}, 
     'fileDataName': 'sampleFile', 
     'folder': '/work/avais/bizlists/lists', 
     'cancelImg': 'include/uploadify/cancel.png', 
     'queueID': 'sampleQueue' 
    }); 
}); 

AFAIK ben "add_list.php" dosyasında yapabileceği tüm nihai dir dosyayı hareket ettirerek yükleme işlemini bitirmek olduğunu; Yanlış bir şey gibi bir şeyleri geri döndürmenin bir yolu olduğunu düşünmüyorum.

Bu dosyayı belirli karakterlere izin vermemek ya da bir çeşit sorun olduğunda bir hata döndürmek için kullanabilmem iyi olurdu, ama sanmıyorum.

Sanırım herhangi bir kötü karakter çıkarıyor olabilirim, ancak bir şekilde bir yanıt verebileceğimi bilmek faydalı olur mu?

+0

olası kopyası [Karşılaşın: HTTP yanıtından hata mesajını göster] (http://stackoverflow.com/questions/1877644/uploadify-show-error-message-from-http-response) –

cevap

7

Sen onComplete işlevi sunucu tarafı komut dosyasından geri gönderilen yanıtın olacak şekilde, tam eylem için ve

$('#sampleFile').uploadify({ 
     'uploader': 'include/uploadify/uploadify.swf', 
     'script': 'add_list.php', 
     'scriptData': {'mode': 'upload'}, 
     'fileDataName': 'sampleFile', 
     'folder': '/work/avais/bizlists/lists', 
     'cancelImg': 'include/uploadify/cancel.png', 
     'queueID': 'sampleQueue' 

    onComplete: function (event, queueID, fileObj, response, data) { 
     // A function that triggers when a file upload has completed. The default 
     // function removes the file queue item from the upload queue. The 
     // default function will not trigger if the value of your custom 
     // function returns false. 
     // Parameters 
     // event: The event object. 
     // queueID: The unique identifier of the file that was completed. 
     // fileObj: An object containing details about the file that was selected. 
     // response: The data sent back from the server. 
     // data: Details about the file queue. 
    }, 

    onError: function (event, queueID, fileObj, errorObj) { 
     // A function that triggers when an error occurs during the upload process. 
     // The default event handler attaches an error message to the queue item 
     // returning the error and changes it's queue item container to red. 
     // Parameters 
     // event: The event object. 
     // queueID: The unique identifier of the file that was errored. 
     // fileObj: An object containing details about the file that was selected. 
     // errorObj: An object containing details about the error returned. 
    } 

}); 

Yani hata kontrol etmek için yükleme komut bazı olay işleyicileri ekleyebilir, dönebilirsiniz istemciye bir yanıt verin ve ardından olay işleyicisindeki yanıtı ayrıştırın. Daha fazla ayrıntı

için Uploadify documentation sizin add_list.php dosyasında yankılandı

+0

Teşekkür ederim - Bilmiyordum Bu işleyiciler, onComplete işlevinin sonucu sunucu tarafı komut dosyasına döndürdüğünü bilmiyordu. :) – Brett

1

şey olur Umut

Kontrol tepki olarak onComplete fonksiyonuna gönderilir. Yani şu yapabileceği: Dosyanın adını isterseniz

$(document).ready(function() { 
$('#sampleFile').uploadify({ 
    'uploader': 'include/uploadify/uploadify.swf', 
    'script': 'add_list.php', 
    'scriptData': {'mode': 'upload'}, 
    'fileDataName': 'sampleFile', 
    'folder': '/work/avais/bizlists/lists', 
    'cancelImg': 'include/uploadify/cancel.png', 
    'queueID': 'sampleQueue', 
    'onComplete' : function(event,ID,fileObj,response,data) { 
     alert(response); 
     } 
    }); 
}); 
+0

Örnek için çok teşekkürler! :) – Brett

0

, kullanmak "gerekir" (doğru yöntemi) fileObj.name: içine çalışabilir herkes için

$(document).ready(function() { 
$('#sampleFile').uploadify({ 
    'uploader': 'include/uploadify/uploadify.swf', 
    'script': 'add_list.php', 
    'scriptData': {'mode': 'upload'}, 
    'fileDataName': 'sampleFile', 
    'folder': '/work/avais/bizlists/lists', 
    'cancelImg': 'include/uploadify/cancel.png', 
    'queueID': 'sampleQueue', 
    'onComplete' : function(event,ID,fileObj,response,data) { 
     alert(fileObj.name); 
     } 
    }); 
});