我正在使用 extjs+PHP[yii 框架]。我正在研究文件上传控制。我有查看代码为-
Ext.define('Balaee.view.kp.dnycontent.Content',
{
extend:'Ext.form.Panel',
requires:[
'Balaee.view.kp.dnycontent.ContentView'
],
id:'ContentId',
alias:'widget.Content',
enctype : 'multipart/form-data',
title:'This day in a history',
items:[
{
xtype: 'fileuploadfield',
hideLabel: true,
emptyText: 'Select a file to upload...',
//inputType: 'file',
id: 'upfile',
name:'file',
width: 220
}],
buttons: [{
xtype : 'button',
fieldlabel:'upload',
action:'upload',
name:'upload',
text: 'Upload',
formBind:'true',
handler: function() {
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url: 'index.php/QuestionBank/Qbpaper/getFile',
waitMsg: 'Uploading your photo...',
// uploadPath:'/app/model',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');
}
});} } }]});
我已经编写了上面的代码来从 extjs4 发送文件。我的服务器端是 PHP [Yii 框架]。在服务器端,我编写了代码来接收这个文件——
public function actiongetFile()
{
$fileName = $_FILES['upfile']['name'];
$fileSize = $_FILES['upfile']['size'];
$fileType = $_FILES['upfile']['type'];
$fp = fopen($fileName, 'r');
$content = fread($fp, filesize($fileName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc()){
$fileName = addslashes($fileName);
}
但服务器端代码无法正常工作。从 extjs 发送文件时,它给出的错误是-“Ext.Error: You're trying to decode an invalid JSON String: PHP notice Undefined index: upfile” 所以在 php 中如何访问通过 extjs4 发送的文件。请帮我