无法在 ubuntu 机器上用 php 打开文件
unable to open file with php on ubuntu machine
我正在尝试使用 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 机器上时,一切都很好
在您的脚本中使用
fopen(dirname(__FILE__) . '/inc/users/future.php', 'w')
这将从您的 index.php 目录创建一个文件路径。如果您的脚本是从另一个文件调用的,php 可能会搜索来自该文件的内容。
还要检查 php 进程是否有足够的 file permissions 来读取和打开文件。尝试将文件设置为 chmod 777
以测试是否是这种情况(但不要将其保留在 777 上)。
请记住,如果文件是符号文件 link,fopen 的 'w' 参数将不起作用。
我正在尝试使用 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 机器上时,一切都很好
在您的脚本中使用
fopen(dirname(__FILE__) . '/inc/users/future.php', 'w')
这将从您的 index.php 目录创建一个文件路径。如果您的脚本是从另一个文件调用的,php 可能会搜索来自该文件的内容。
还要检查 php 进程是否有足够的 file permissions 来读取和打开文件。尝试将文件设置为 chmod 777
以测试是否是这种情况(但不要将其保留在 777 上)。
请记住,如果文件是符号文件 link,fopen 的 'w' 参数将不起作用。