简体   繁体   English

为什么不能将网页保存到我的/ var / www目录中?

[英]Why can't save the web page into my /var/www directory?

The document root is /var/www, I want to download the web page into /var/www/php.html 文档根目录是/ 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;
?>

I can get the web page in firefox, but where is my php.html file ? 我可以在firefox中获得该网页,但是我的php.html文件在哪里?

Your page is located in the same folder of your PHP script. 您的页面位于PHP脚本的同一文件夹中。 If you want access to the page you should something like use http://path_to_your_script/pythons.html 如果您想访问该页面,则应该使用http://path_to_your_script/pythons.html

To save in your /var/www you should use this: 要保存在/ 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;
?>

Now you can access with http://localhost/php.html 现在您可以使用http://localhost/php.html进行访问

If you can't save in /var/www/ is because you don't have permission, if you have root permission you can execute this in the console: sudo chmod 777 /var/www/ 如果您由于没有权限而无法保存在/ var / www /中,则如果您具有root权限,则可以在控制台中执行此操作: sudo chmod 777 /var/www/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM