【问题标题】:uploadFile does not posts image to server file (PHP)uploadFile 不会将图像发布到服务器文件(PHP)
【发布时间】:2020-03-02 10:28:10
【问题描述】:

在我的应用程序中,我有 cordova camera 插件,它允许我拍照并从中获取 URI。

const options: CameraOptions = {
  quality: 100,
  destinationType: this.camera.DestinationType.FILE_URI,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE
};
this.camera.getPicture(options).then(
  imageURI => {

  },
  err => {

  }
);

然后我使用该 URI 上传到我的服务器。

this.http
    .uploadFile(
        'https://example.com/pages/attachments.php, {
            action: 'INSERT'
        }, {},
        'file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1583144250046.jpg',
        'picture'
    )
    .then(
        fileResult => {
            console.log(fileResult);
        },
        err => {

        }
    );

但是我从console.log 结果中得到了这些错误:

未定义索引:文件在第 1235 行

未定义的索引:文件在第 1236 行

这些是attachments.php中的行:

// The tmp_name is the name of the temporary file on the server.
$tmp_name = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
    

$_FILES 似乎是空的,但我不知道为什么。我假设使用http.uploadFile 会发送文件,但我不确定为什么不是。有什么帮助吗?

【问题讨论】:

    标签: ionic-framework file-upload cordova-plugin-advanced-http


    【解决方案1】:

    似乎是与您的 PHP 代码有关的问题。检查this文件, 我认为file 是错误的。也许您应该改用picture,因为您在上传文件时使用了这个名称?但我不是 PHP 专家。

    【讨论】:

      【解决方案2】:

      根据您的 JS 代码,您应该使用 $_FILES['picture']

      您使用的是 PHP 框架吗?我建议您这样做,以使您的文件上传处理更加稳健和安全。

      【讨论】:

        猜你喜欢
        • 2021-12-06
        • 2014-06-25
        • 1970-01-01
        • 1970-01-01
        • 2020-11-25
        • 1970-01-01
        • 2012-08-15
        • 2015-09-13
        • 1970-01-01
        相关资源
        最近更新 更多