我是使用 extjs 的新手。而且我一直很难将图像上传到服务器。我已经看到了很多我作为指导的例子。但我似乎可以得到一个成功的结果。
这是我的观点的代码:
items: [{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select image',
name: 'image-upload',
buttonText: 'Browse',
buttonConfig: {
iconCls: 'upload-icon'
}
},
{
xtype: 'button',
//action: 'submit',
text: 'Upload',
handler: function(){
var form = this.up('form').getForm();
form.submit({
url: 'uploadproc.php',
waitMsg: 'Loading data...',
success: function(fp, o) {
msg('Success', 'Processed file "' + o.result.file + '" on the server');
}
});
}
}
],
这是我的 uploadproc.php 文件
<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["image-upload"]["name"]);
$extension = end($temp);
if ((($_FILES["image-upload"]["type"] == "image/gif")
|| ($_FILES["image-upload"]["type"] == "image/jpeg")
|| ($_FILES["image-upload"]["type"] == "image/jpg")
|| ($_FILES["image-upload"]["type"] == "image/pjpeg")
|| ($_FILES["image-upload"]["type"] == "image/x-png")
|| ($_FILES["image-upload"]["type"] == "image/png"))
&& ($_FILES["image-upload"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["image-upload"]["error"] > 0)
{
echo "Return Code: " . $_FILES["image-upload"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["image-upload"]["name"] . "<br>";
echo "Type: " . $_FILES["image-upload"]["type"] . "<br>";
echo "Size: " . ($_FILES["image-upload"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["image-upload"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["image-upload"]["name"]))
{
echo $_FILES["image-upload"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["image-upload"]["tmp_name"],
"upload/" . $_FILES["image-upload"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["image-upload"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
我不断收到此错误:
Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String: Invalid file
我将uploadproc.php 文件保存在我的文件夹内但在js 文件夹之外。我对此真的很陌生,如果有人可以帮助我。非常感谢。