1

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.";
?>
1
  • You usually do not want any request trying to overwrite any file. Secure your GET parameter. Disable that values like "/etc/passwd" are executed and overwrite files you do not want. Your non-working hoster might have security implemented to prevent this. Commented Oct 24, 2012 at 0:00

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.