2016-04-28 76 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)); 
相关问题