为什么没有协议,file_get_contents()不起作用? [英] Why file_get_contents() doesn't work without protocol?
本文介绍了为什么没有协议,file_get_contents()不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
版本1: 我有这样的代码也可以正常工作:
Version1: I have this code which works as well:
file_put_contents("../img/avatar/".$id.".jpg", file_get_contents("http://localhost/folder/script.php?id=$id"));
版本2:现在,我需要在file_get_contents
中编写一个没有协议的路径,所以这是我的代码的新版本.但这不起作用:
Version2: Now I need to write a path without protocol in file_get_contents
, So here is the new version of my code. But it doesn't work:
$_GET['id'] = $id;
file_put_contents("../img/avatar/".$id.".jpg", file_get_contents("../folder/script.php"));
版本2有什么问题?
注意: script.php
进行化身.并且 version1 也会创建该图像,但是 version2 只会创建一个未知图像.
Note: script.php
makes a avatar. And version1 creates that image as well but version2 just creates a unknown image.
推荐答案
由于您的script.php
包装在函数中,因此您将首先包含文件,然后使用该函数作为输入数据.
Since your script.php
is wrapped in a function, you would include the file first and then use that function as your input data.
require_once(__DIR__ . '/../../out/script.php');
file_put_contents("../img/avatar/".$id.".jpg", MakeAvatar($id));
这篇关于为什么没有协议,file_get_contents()不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文