写入php文件时无法打开文件

写入php文件时无法打开文件,php,fopen,file-handling,Php,Fopen,File Handling,我正在尝试使用fopen和fwrite $book="http://bittotb.com/synthesis_study_material/student_admin/include/uploaded/epub/923960_hotel (1).epub"; $path=$book.".php"; $myfile =fopen($path, "w"); $txt = "<?php include('hello.php'); ?>"; fwrite($myfile, $txt); f

我正在尝试使用fopen和fwrite

$book="http://bittotb.com/synthesis_study_material/student_admin/include/uploaded/epub/923960_hotel (1).epub";
$path=$book.".php";
$myfile =fopen($path, "w");
$txt = "<?php include('hello.php'); ?>";
fwrite($myfile, $txt);
fclose($myfile);
然后它在同一个目录中创建一个文件,但我想在另一个目录中创建该文件。当使用path时,它不起作用。如果我回显$path,那么我将

http://bittotb.com/synthesis_study_material/student_admin/include/uploaded/epub/923960_hotel (1).epub.php

这是正确的文件名和路径,但仍然使我无法打开文件,我的文件夹权限显示为0777

您必须使用服务器上的路径,而不是页面的URL

例如,您的页面可以有URL
http://example.org/index.php
。该文件可以位于名为
/var/www/example.org/index.php的服务器上

使用此代码确定您的目录:

<?php
echo getcwd();

如果要写入文件
http://bittotb.com/synthesis_study_material/student_admin/include/uploaded/epub/file.php
来自脚本
http://bittotb.com/synthesis_study_material/student_admin/module/corses/file.php
,使用相对路径:

$file = fopen("../../include/uploaded/epub/file.php", "w");
// ...

我猜空格可能是个问题,或者是
/
-从这个字符串创建哈希并将其用作文件名。你可能必须
http:/bittob.com/synthesis\u study\u material/student\u admin/include/upload/epub
。现在我已经使用str\u replace和replace space from\u,但问题仍然存在,记住0777意味着每个用户都在使用机器可以读取、写入和执行它(对于目录执行意味着读取文件列表)。如果您正在使用某些公共托管,其他网站可以访问您的数据。Unix模式是这些值的总和:1=执行,2=写入,4=读取。对于三位数字,第一位表示所有者,第二位表示所有者组,第三位表示其他所有人。左边可能还有一个数字(您有0=默认值)修改行为。是的,它会生成,但我的文件在中,我想在@vivekmodi中生成此文件,但您必须使用服务器上的路径,而不是URL。我们如何生成权限为0775的文件,以便任何人都可以打开此文件file@vivekmodi使用。示例:
chmod(“../../foo.txt”,0775)
(始终在数字前使用零!)
0775
表示所有者和组可以读取、写入和执行文件,其他人可以读取和执行文件。你想要文件可执行文件吗?是的,我想要文件可执行文件,但在我的代码中添加chomd后,我得到500个内部服务器错误
$file = fopen("test.php", "w");
fwrite($file, "<?php echo 'Hello World'; ?>");
fflush($file);
fclose($file);
$file = fopen("../../include/uploaded/epub/file.php", "w");
// ...