文档根目录是/var/www,我想把网页下载到/var/www/php.html
<?php
$url = "http://php.net";
$html_content = file_get_contents($url);
$fp = fopen("php.html","a");
fwrite($fp,$html_content);
fclose($fp);
echo $html_content;
?>
我可以在 Firefox 中获取网页,但是我的 php.html 文件在哪里?
最佳答案
您的页面位于 PHP 脚本的同一文件夹中。如果您想访问该页面,您应该使用 http://path_to_your_script/pythons.html
要保存在/var/www 中,您应该使用:
<?php
$url = "http://localhost/postgres";
$html_content = file_get_contents($url);
$fp = fopen("/var/www/php.html","a"); // ADD /var/www to the path
fwrite($fp,$html_content);
fclose($fp);
echo $html_content;
?>
现在您可以通过 http://localhost/php.html 访问
如果无法保存到/var/www/是因为没有权限,如果有root权限可以在控制台执行:sudo chmod 777/var/www/
关于php - 为什么无法将网页保存到我的/var/www目录中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29058151/