duanjianqu3685 2012-09-25 13:17
浏览 33
已采纳

PhoneGap FileTransfer和Server端脚本

I'm stucked with this for the whole day, the JavaScipt code seems fine. But in the output i get this:

2012-09-25 15:09:57.584 ViviJesolo[13863:c07] File Transfer Finished with response code 200
2012-09-25 15:09:57.586 ViviJesolo[13863:c07] [INFO] Code = 200
2012-09-25 15:09:57.586 ViviJesolo[13863:c07] [INFO] Response = Array%0A(%0A%20%20%20%20%5Bfile%5D%20=%3E%20Array%0A%20%20%20%20%20%20%20%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5Bname%5D%20=%3E%20cdv_photo_027.jpg%0A%20%20%20%20%20%20%20%20%20%20%20%20%5Btype%5D%20=%3E%20image/jpg%0A%20%20%20%20%20%20%20%20%20%20%20%20%5Btmp_name%5D%20=%3E%20/tmp/php4i7HAa%0A%20%20%20%20%20%20%20%20%20%20%20%20%5Berror%5D%20=%3E%200%0A%20%20%20%20%20%20%20%20%20%20%20%20%5Bsize%5D%20=%3E%202340%0A%20%20%20%20%20%20%20%20)%0A%0A)%0A
2012-09-25 15:09:57.587 ViviJesolo[13863:c07] [INFO] Sent = 2548

My server side script is:

<?php
print_r($_FILES);
$new_image_name = "namethisimage.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "/httpdocs/upload/".$new_image_name);
?>

I've checked the permissions and it's ok, but i can't see the uploaded file. What could be the problem?

Edit: I'm uploading the image using FileTransfer object like this:

function uploadPhoto(imageURI) 
{
 var options = new FileUploadOptions(); 
 options.fileKey="file"; 
 options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
 options.mimeType="image/jpg";
 var params = new Object();
 params.headers={'headerParam':'headerValue'};
 options.params = params;
 options.chunkedMode = false;
 var ft = new FileTransfer();
 ft.upload(imageURI, "site.com/upload.php";, win, fail, options); 
} 
  • 写回答

1条回答 默认 最新

  • doubo4824 2012-09-25 13:33
    关注

    It may be you had the destination file path wrong, try appending your path to the document root, like this:

    $new_image_name = "namethisimage.jpg";
    $destination = $_SERVER['DOCUMENT_ROOT'] . "/httpdocs/upload/".$new_image_name;
    move_uploaded_file($_FILES["file"]["tmp_name"], $destination);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛