douqujin2767 2016-02-16 11:57
浏览 283
已采纳

cordova-plugin-file-transfer不上传文件到服务器

I'm working on cordova project that uploads photos to server. While testing this for android, success callback is called but file not uploaded to server. Destination folder in server is present with necessary permission.

Following is the Javascript section

var options = new FileUploadOptions();
options.fileKey  = "myphoto";
options.fileName = filetoupload.substr(filetoupload.lastIndexOf('/')+1);
options.mimeType = "image/jpeg";
options.chunkedMode = false;
options.headers = {
    Connection: "close"
};
var ft = new FileTransfer();
ft.upload(filetoupload, encodeURI(websrvs_base_url), win, fail, options);

In server PHP code is

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS");
header("content-type: application/json; charset=utf-8");

if($_FILES['myphoto']['size'] > 0) {
    $path = $ROOT_PATH . "mypics/";
    $tmpname1 = $_FILES['myphoto']['tmp_name'];
    $ptname1 = $_FILES['myphoto']['name'];
    move_uploaded_file($tmpname1, $path . $ptname11);

    echo 'success';
}

On checking $_FILES['myphoto']['error'] returns 7

Server has following setting regarding file upload

file_uploads - On

memory_limit - 128M

post_max_size - 64M

upload_max_filesize - 100M

Should I added any additional headers in PHP script to receive the file from app?

  • 写回答

1条回答 默认 最新

  • dongzhong9055 2016-02-26 06:29
    关注

    It turned out to be a server issue, our demo server was disk full and it didn't allow uploading photos from app.

    We will have to check the space available for /tmp folder in server as this will be used as a temporary storage before uploading the file to actual destination. Files will not upload if /tmp folder is full or if there is any limitation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)