2013-04-02 3 views
5

extjs + php에서 파일 업로드 기능을 연구 중입니다. 내가 extjs에서 파일이나 이미지를 업로드하고 PHP에서 설계 오전 서버 측에 보내야합니다. extjs에서 나는 파일의 코드를 볼 수있다 -extjs에서 업로드 된 파일의 내용을 얻는 방법

Ext.define('Balaee.view.kp.dnycontent.Content', 
{ 
    extend:'Ext.panel.Panel', 
    requires:[ 
       'Balaee.view.kp.dnycontent.ContentView' 
       ], 
    id:'ContentId', 
    alias:'widget.Content', 
    title:'This day in a history', 
    items:[ 
    { 
     xtype: 'fileuploadfield', 
     hideLabel: true, 
     emptyText: 'Select a file to upload...', 
     id: 'upfile', 
     //name:'file', 
     width: 220 
}], 
    buttons:[ 
    { 
     text: 'Upload', 
     handler: function() { 
      var file = Ext.getCmp('upfile').getEl().down('input[type=file]').dom.files[0];   console.log(file); 
      var reader = new FileReader(); 
      filecontent=reader.readAsBinaryString(file); 
      console.log(filecontent); 
     } 
    } 
] 

});

그래서 라인 위의 위의 code.The과를 Animage 파일을 업로드하려고 할 때 : 파일 관련

File { 
    webkitRelativePath: "", 
    lastModifiedDate: Tue Jul 14 2009 11:02:31 GMT+0530 (India Standard Time), 
    name: "Koala.jpg", 
    type: "image/jpeg", 
    size: 780831… 
} 

즉 정보를 검색 : 같은 파일의 Ext.getCmp('upfile').getEl().down('input[type=file]').dom.files[0]; 정보를 저장합니다. 그러나 실제 파일 내용은 검색되지 않습니다. 그렇다면 실제 업로드 된 파일을 수정하려면 무엇이 필요합니까?

답변

2

파일의 내용이 readAsBinaryString에서 반환되지 않으면 파일 내용을 읽을 때 트리거되는 onload 콜백을 설정해야합니다.

reader.onload = function (oFREvent) { 
    console.log(oFREvent.target.result); 
}; 
+0

고맙습니다 선생님 ... 나는 그것으로 파일을 얻고 모든 내용 ... – user1722857

+0

@ user1722857 당신이 아약스를 통해 파일을 업로드하기위한 시도로 서버에 문자열을 업로드 하시겠습니까? 그렇다면 대신 [FormData] (https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/FormData)를 사용해야합니다. – Musa

+1

실은 이제 선생님, 저는 서버쪽에 무엇을 보낼지에 집착했습니다. 내가 "Ext.getCmp ('upfile'). getEl(). down ('input [type = file]')에 의해 검색된 서버에 파일과 관련 정보 만 보내야하는지 여부. dom.files [0]; " 그러나 파일의 내용이 서버 측으로 전송되는 방법은 무엇입니까? 업로드 된 파일을 서버 측에 전송하려면 어떤 수정이 필요합니까? 제발 나를 안내해 주시겠습니까? – user1722857

관련 문제