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 我用C语言easyx图形库绘制了一个3d游戏方框透视,但进入游戏时候鼠标准星对准方框边缘 鼠标光标就会弹出来这是啥情况怎样让光标对准绘制的方框点击鼠标不弹出光标好烦这样
    • ¥20 用Power Query整合的问题
    • ¥20 基于python进行多背包问题的多值编码
    • ¥15 相同型号电脑与配置,发现主板有一台貌似缺少了好多元器件似的,会影响稳定性和使用寿命吗?
    • ¥15 要求编写稀疏矩阵A的转置矩阵的算法
    • ¥15 编写满足以下要求的停车场管理程序,设停车场只有一个可停放n辆车的狭窄通道且只有一个大门可供车辆进出。
    • ¥15 C语言:数据子序列基础版
    • ¥20 powerbulider 导入excel文件,显示不完整
    • ¥15 用keil调试程序保证结果进行led相关闪烁
    • ¥15 paddle训练自己的数据loss降不下去