【问题标题】:Why can't save the web page into my /var/www directory?为什么不能将网页保存到我的 /var/www 目录中?
【发布时间】:2015-05-17 11:09:38
【问题描述】:

文件根目录是/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 linux file file-get-contents document-root


【解决方案1】:

您的页面位于 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/

【讨论】:

  • 如果不能保存是因为没有权限,如果有root权限可以在控制台执行:sudo chmod 777 /var/www/
猜你喜欢
  • 1970-01-01
  • 2021-12-20
  • 1970-01-01
  • 1970-01-01
  • 2015-01-05
  • 1970-01-01
  • 1970-01-01
  • 2015-06-30
  • 2021-02-23
相关资源
最近更新 更多