2011-02-23 2 views
2

아래 코드는 업로드 부분을 제외하고 작동합니다. 지금까지 문제없이 스크립트를로드 할 수 있으며 사용자가 업로드 버튼을 클릭하면 파일 대화 상자가 열립니다.SWFUpload는 어떻게 작동합니까?

그러나 내가하려는 것은 다른 텍스트 입력 및 텍스트 영역 요소가 포함 된 양식에 파일을 할당하는 것입니다.

기본적으로 나는이 작업을 수행하려고 :

  1. 사용자 값으로 양식을 채워
  2. 사용자가 SWFUpload
  3. 사용자를 사용하여 파일을 선택합니다 (예 : 텍스트 입력, 텍스트 영역 필드를 채우고) 양식 제출

양식을 파일 입력 요소에 연결하여 양식을 수동 제출하면 모든 값이 한 번에 전송됩니까?

내가 아는 한, SWFUpload는 백그라운드에서 자동으로 파일을 제출하는 데 사용됩니다 ... 대신이 파일을 수동으로 하나의 양식으로 만들 수 있습니까?

 $('.swfupload-control').swfupload({ 

     // File Upload Settings 
     file_size_limit : "102400", // 100MB 
     file_types : "*.*", 
     file_types_description : "All Files", 
     file_upload_limit : "10", 
     file_queue_limit : "0", 

     // Button Settings 
     button_image_url : "/images/upload_song.gif", // Relative to the SWF file 
     button_placeholder_id : "spanButtonPlaceholder", 
     button_width: 186, 
     button_height: 32, 

     // Flash Settings 
     flash_url : "/javascripts/swfupload/swfupload.swf" 

    }); 


    $('.swfupload-control') 
     .bind('swfuploadLoaded', function(event){ 
      $('#log').append('<li>Loaded</li>'); 
     }) 
     .bind('fileQueued', function(event, file){ 
      $('#log').append('<li>File queued - '+file.name+'</li>'); 

      //$('#song_attachment').val(file); 

      $('#update-media').parents('li').find('p').remove(); 
      $('#update-media').parents('li').append('<p>'+(file.name.length >= 45 ? file.name.substr(0, 45) + '...' : file.name)+'</p>'); 
      // start the upload since it's queued 
      //$(this).swfupload('startUpload'); 
     }) 
     .bind('fileQueueError', function(event, file, errorCode, message){ 
      $('#log').append('<li>File queue error - '+message+'</li>'); 
     }) 
     .bind('fileDialogStart', function(event){ 
      $('#log').append('<li>File dialog start</li>'); 
     }) 
     .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){ 
      $('#log').append('<li>File dialog complete</li>'); 
     }) 
     .bind('uploadStart', function(event, file){ 
      $('#log').append('<li>Upload start - '+file.name+'</li>'); 
     }) 
     .bind('uploadProgress', function(event, file, bytesLoaded){ 
      $('#log').append('<li>Upload progress - '+bytesLoaded+'</li>'); 
     }) 
     .bind('uploadSuccess', function(event, file, serverData){ 
      $('#log').append('<li>Upload success - '+file.name+'</li>'); 
     }) 
     .bind('uploadComplete', function(event, file){ 
      $('#log').append('<li>Upload complete - '+file.name+'</li>'); 
      // upload has completed, lets try the next one in the queue 
      $(this).swfupload('startUpload'); 
     }) 
     .bind('uploadError', function(event, file, errorCode, message){ 
      $('#log').append('<li>Upload error - '+message+'</li>'); 
     }); 

답변

1

미안 해요, SWF 업로드를 알고 관련이없는 경우이 대답을 삭제 준비가 ...하지만하지 않습니다 Uploadify과 하나 https://github.com/apneadiving/Pic-upload---Crop-in-Ajax

하나 :

내가 여기 두 개의 응용 프로그램을 만든 jQuery-File-Upload.

두 사람 모두 사용자의 요구에 응답합니다 (제출하는 아약스, 여러 파일 업로드). Jquery 파일은 플래시가 필요 없기 때문에 업로드하는 것이 좋습니다.

내가 여기 자습서를 썼다 : https://github.com/blueimp/jQuery-File-Upload/wiki/jQuery-File-Upload-for-Rails-3

+0

+1 멋진 조각을 볼 수있는 자바 스크립트 파일 API에 대한 몇 가지 지원을하고있다 – Thariama

1

가 아니, 파일 필드에 SWFUpload 후크 수 없습니다.

브라우저는 전통적으로 사용자의 파일 시스템에 대한 자바 스크립트 액세스를 허용하지 않습니다 (작품에 API가 있음). SWFUpload는 Flash API를 사용하여 사용자의 파일 시스템에서 직접 파일을 읽고 서버로 스트리밍하여이 문제를 해결합니다. 이렇게하려면 Flash가 파일 시스템의 파일에 대한 직접 핸들을 필요로합니다. 파일 핸들은 파일 입력 또는 자바 스크립트를 통과 할 수 없습니다.

파이어 폭스, 작업의 https://developer.mozilla.org/en/using_files_from_web_applications