Lokesh Basu
Lokesh Basu

Reputation: 31

Uploading image in Android app using php script

Heyy..i am using a php script to upload an image file from android app. I use HTTP Post function to upload the file(I call www.masterstroketech.org/postimage.php?fn=abc.png and then post image path). The file is being created on the server, but its size is 0 bytes.

If i use the same script on a free server at 000webhost.com then this script runs fine. What exactly is the problem?

php code is as follows :

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

Upvotes: 1

Views: 335

Answers (1)

rgrocha
rgrocha

Reputation: 1461

Extracted from the file_get_contents doc at php.net:

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.

So seems like a problem with your local server configuration.

Upvotes: 1

Related Questions