我正在尝试传递我在移动设备中拍摄的图像以保存在我的服务器中。服务器端是用 php 编码的。这是javascript代码:
var options = new FileUploadOptions();
options.fileKey = "image";
options.fileName = newPlace.id;
options.mimeType="image/jpeg";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(cameraImg, "http://www.myserver.com/upload.php", imageUploaded, imageUploadedError, options);
服务器端代码为:
<?php
if(isset($_FILE['image'])) {
echo "good";
$ourFileName = "good.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$file_name = $_FILE['image']['name'];
$file_tmp = $_FILE['image']['tmp_name'];
move_uploaded_file($file_tmp, 'images/'.$file_name);
}
else {
echo "not good";
}
?>
我知道我正在连接到服务器并且 php 代码正在运行,但它没有捕获 `if(isset($_FILE['image']))。我知道这一点是因为我收到一条警告,上面写着“响应:不好”。我的错误在哪里?提前致谢!