簡體   English   中英

編寫php文件時無法打開文件

[英]Unable to open file while writing php file

我正在嘗試使用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);

當我只是在fopen中寫文件名時

$myfile =fopen("abc.php", "w");

然后它在同一目錄中創建一個文件,但我想在另一個目錄中創建該文件。 當我使用路徑時,如果我回應$ 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();

如果上面的代碼顯示/var/www/example.org/ ,則文件http://example.org/test.php具有文件路徑/var/www/example.org/test.php 但最好使用相對路徑。 (見下文)


如果您有http://example.org/index.php頁面並且想要創建http://example.org/test.php ,請使用以下命令:

$file = fopen("test.php", "w");
fwrite($file, "<?php echo 'Hello World'; ?>");
fflush($file);
fclose($file);

如果你想寫入文件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");
// ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM