![](/img/trans.png)
[英]I can not copy a file in PHP to another directory out of /var/www in my apache2 web server
[英]Why can't save the web page into my /var/www directory?
文档根目录是/ 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/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.