doushan1157 2013-04-27 20:24
浏览 27
已采纳

使用phonegap将图像传输到php时出错

I am trying to pass image that I took in my mobile device to be saved in my server. the server side is coded in php. here is the javascript code:

var options = new FileUploadOptions();
                        options.fileKey = "image";
                        options.fileName = newPlace.id;
                        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(cameraImg, "http://www.myserver.com/upload.php", imageUploaded, imageUploadedError, options);

The server side code is:

<?php
    if(isset($_FILE['image'])) {
        echo "good";
            $ourFileName = "good.txt";
        $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
        fclose($ourFileHandle);
        $file_name = $_FILE['image']['name'];
        $file_tmp = $_FILE['image']['tmp_name'];
        move_uploaded_file($file_tmp, 'images/'.$file_name);

    }
    else {
        echo "not good";
    }
?>

I know I am connecting to the server and the php code is running but it is not catching the `if(isset($_FILE['image'])). I know this because I am getting an alert that says "response: not good". Where is my mistake? Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongza6247 2013-04-28 06:35
    关注

    Ok then, I have changed $_FILE to $_FILES and it worked.

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?