[英]Phonegap image upload fail to upload
I am follow this tutorial for uploading images to a server using Phonegap. 我正在按照本教程使用Phonegap将图像上传到服务器。 The data gets sent to the server but fails to upload.
数据已发送到服务器,但无法上传。 This is the response I get when I try to upload a picture to my server.
这是我尝试将图片上传到服务器时得到的响应。
here is my php code 这是我的PHP代码
<?php
header("access-control-allow-origin: *");
print_r($_FILES);
$new_image_name = "image.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "/products/".$new_image_name);
?>
and here is my function to run the whole thing on my app 这是我在应用程序上运行整个程序的功能
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
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(imageURI, "http://clubbedin.clanteam.com/upload.php", win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
alert(r.response);
}
function fail(error) {
alert("An error has occurred: Code = " = error.code);
}
Here is the structure for the server 这是服务器的结构
the path is wrong, in that case. 在这种情况下,路径是错误的。 /products/ might be at the root when you log in, but the web user might have a different root.
/ products /可能是您登录时的根目录,但Web用户可能具有不同的根目录。 It's worth checking, at least - if you upload a PHP file containing just echo(getcwd());
至少值得检查一下-如果您上传的PHP文件仅包含echo(getcwd()); they should show you what PHP thinks the path is.
他们应该告诉您PHP认为路径是什么。 - @andrewsi
-@安德鲁西
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.