1

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.";
?>
4

1 回答 1

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.

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

于 2012-10-24T08:07:58.820 回答