2016-04-28 79 views
0

版本1: 我有這個代碼的作品,以及:爲什麼file_get_contents()在沒有協議的情況下無法工作?

file_put_contents("../img/avatar/".$id.".jpg", file_get_contents("http://localhost/folder/script.php?id=$id")); 

版本2:現在我需要寫沒有協議的路徑file_get_contents,因此,這裏是我的代碼的新版本。但它不起作用:

$_GET['id'] = $id; 
file_put_contents("../img/avatar/".$id.".jpg", file_get_contents("../folder/script.php")); 

版本2有什麼問題?


注:script.php使一個頭像。並且版本1也會創建該圖像,但版本2只會創建未知圖像。

+1

'file_get_contents()'不解釋PHP代碼,它只是讀取文件。它通過'http://'隧道傳輸的原因是因爲你的http服務器解釋它,並返回結果。 – Havenard

+0

http://php.net/manual/en/function.error-reporting.php –

+0

@ Fred-ii-沒有錯誤。剛剛保存的照片是未知的。 – stack

回答

2

由於您的script.php包裝在一個函數中,因此您將首先包含該文件,然後將該函數用作輸入數據。

require_once(__DIR__ . '/../../out/script.php'); 
file_put_contents("../img/avatar/".$id.".jpg", MakeAvatar($id)); 
相關問題