使用php脚本在Android应用程序中上传图像

时间:2012-10-23 23:51:22

标签: php android http

Heyy ..我正在使用php脚本从Android应用程序上传图像文件。我使用HTTP Post函数上传文件(我打电话给www.masterstroketech.org/postimage.php?fn=abc.png,然后发布图片路径)。该文件正在服务器上创建,但其大小为0字节。

如果我在000webhost.com上的免费服务器上使用相同的脚本,则此脚本运行正常。究竟是什么问题?

php代码如下:

   <?PHP
   $data = file_get_contents('php://input');
   if (!(file_put_contents($_GET['fn'],$data) === FALSE)) echo "File xfer completed.";    // file could be empty, though
   else echo "File xfer failed.";
?>

1 个答案:

答案 0 :(得分:1)

从php.net上的file_get_contents文档中提取:

Reading all script input is simple task with file_get_contents, but it depends on what SAPI is being used.

Only in Apache, not in CLI:
<?php
  $input = file_get_contents("php://input");
?>

Only in CLI, not in Apache:
<?php
  $input = file_get_contents("php://stdin");
?>

In Apache php://stdin will be empty, in CLI php://input will be empyt instead with no error indication.

因此,您的本地服务器配置似乎有问题。