[英]Yii framework: Save uploaded file
I'm using Yii framework for developing website. 我正在使用Yii框架来开发网站。 Here, I have a problem in save image file which uploaded to server.
在这里,我在保存上传到服务器的图像文件时遇到问题。
Here is the code which I used for uploading image. 这是我用于上传图像的代码。
<input type="file" onChange="uploadImage(this);">
function uploadImage(obj) {
var request_url = server_url + "uploadImage";
var formData = new FormData();
formData.append("photo", obj.files[0]);
$.ajax({
url: request_url,
type: 'POST',
data: formData,
processData: false,
contentType:false
});
}
And in server part, I can see the file has uploaded but can't get the file. 在服务器部分,我可以看到文件已上传但无法获取文件。
public function actionUploadImage() {
if (ISSET($_FILES['photo'])) {
var_dump('is set photo');
$temp = CUploadedFile::getInstanceByName('photo');
var_dump($temp);
}
}
It returns "is set photo" and "array(0){}". 它返回“已设置照片”和“ array(0){}”。 Please help me.
请帮我。
You are uploading images using jquery/ajax
. 您正在使用
jquery/ajax
上传图像。 You need to include jquery and their corresponding function. 您需要包括jquery及其相应的功能。
Here is one of tutorial to upload images using jquery - 这是使用jquery上传图像的教程之一-
http://www.9lessons.info/2013/09/multiple-ajax-image-upload-jquery.html
You could google for other tutorials. 您可以通过Google搜索其他教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.