2015-11-21 46 views
0

我想在另一個名爲「files」的目錄中創建一個文件。在另一個目錄上使用PHP創建文件

我的服務器看起來是這樣的:

root: 
    createfile.php 
    files: 
     file1.txt 

這是我曾嘗試:

$myfile = fopen("../files/file2.txt", "w")or die("Unable to open file!"); 

但是當我運行畝代碼,它給了我這個錯誤:

Warning: fopen(../files/file2.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\createfile.php on line 4 
+1

減去'../'部分和你的好 – Rizier123

回答

0

如果PHP文件和要創建文件的文件夾存在於同一文件夾中,則不需要「../」。目前的含義是文件目錄與根目錄處於同一級別。只要刪除它,它應該工作。

$myfile = fopen("files/file2.txt", "w")or die("Unable to open file!"); 
0

請嘗試下面的代碼來創建新文件。

<?php 
echo file_put_contents("test.txt","Hello World. Testing!"); 
?> 
相關問題