2012-10-23 34 views
1

Heyy ..我正在使用php腳本從android應用程序上傳圖像文件。我使用HTTP Post功能上傳文件(我打電話給www.masterstroketech.org/postimage.php?fn=abc.png,然後發佈圖像路徑)。該文件正在服務器上創建,但其大小爲0字節。使用php腳本在Android應用程序中上傳圖像

如果我在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."; 
?> 
+0

您通常不希望嘗試覆蓋任何文件的任何請求。確保您的GET參數。禁用像「/ etc/passwd」這樣的值會被執行並覆蓋你不想要的文件。您的非在職託管方可能已實施安全措施來防止這種情況發生。 – Sven

回答

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. 

所以看起來像本地服務器配置的問題。

+1

這個答案工作! 謝謝。 :) –

相關問題