无法在ubuntu机器上用php打开文件

时间:2017-09-13 13:18:52

标签: php ubuntu fopen

我尝试使用PHP脚本在Ubuntu系统中创建新文件, 但是当我运行此脚本时出现错误

Unable to Open file 

出现 虽然我确定该文件的路径是正确的,我有权访问此文件,但我不知道哪里出错了 这是我的代码

$myfile = fopen('inc/users/future.php', "w")or die("Unable to open file!") ;
$text='<?
$host ="'.$host.'";
 $user ="'.$db_admin.'" ;
 $pass ="'.$db_password.'";
 $db ="'.$database.'" ;
$myconn;?>';fwrite($myfile, $text);
fclose($myfile);

此脚本的路径是

  

/var/www/html/ghost/index.php

和我想打开的文件的路径是

  

/var/www/html/ghost/inc/users/future.php

另一方面,当我在windows机器上运行这个脚本时,每件事情都很顺利

1 个答案:

答案 0 :(得分:0)

在您的脚本中使用

fopen(dirname(__FILE__) . '/inc/users/future.php', 'w')

这将从index.php目录创建一个文件路径。如果从另一个文件调用脚本,php可能会搜索来自该文件。

同时检查php进程是否有足够file permissions来读取和打开文件。尝试将文件设置为chmod 777只是为了测试是否是这种情况(尽管不要将其保留在777上)。

请注意,如果文件是符号链接,那么&#39; w&#39; fopen的参数不起作用。