1
A
回答
4
您可以使用file_put_contents。
<?php
file_put_contents("/home/public_html/files/hi.txt", "content");
?>
或者touch如果你不需要的內容,只是希望確保該文件被創建:
<?php
touch("/home/public_html/files/hi.txt");
?>
0
file_put_contents("/home/public_html/files/hi.txt",$data);
0
你可以/應該使用原生PHP函數:
file_put_contents('/home/public_html/files/hi.txt', 'lorem ipsum')
1
也可以嘗試fopen("/path/to/file", 'w')
「W」 將根據the docs「如果文件不存在,試圖創建它。 「
0
也許this是對某些人詢問是否使用file_put_contents()
或touch()
0
簡單:
fwrite($file = fopen($filename, "w"), "New content");
fclose($file);
如果文件不包含任何內容:
fclose($file = fopen($filename, "w"));
而且,檢查文件是否存在與file_exists()以防止清除現有文件的內容:
if (!file_exists($filename))
fclose($file = fopen($filename, "w"));
相關問題
- 1. 在PHP中創建一個php文件
- 2. 在php中創建一個文件
- 3. PHP - 無法創建一個XML文件
- 4. 創建一個txt文件失敗,PHP
- 5. 創建一個PHP文件單獨
- 6. 在php中創建一個.sql文件
- 7. 用代碼創建一個PHP文件
- 8. PHP創建一個XML文件
- 9. PHP創建一個json文件
- 10. php exec() - mysqldump創建一個空文件
- 11. 用PHP創建一個CSV文件
- 12. 使用PHP創建一個zip文件
- 13. 我想創建一個PHP文件鏈接到另一個PHP文件
- 14. 創建php文件
- 15. 創建一個.jar文件
- 16. 創建一個make文件
- 17. 創建一個plist文件
- 18. 創建一個exe文件
- 19. 創建一個Dll文件
- 20. 創建一個xml文件
- 21. 創建一個AVI文件
- 22. 創建一個CSV文件
- 23. 創建一個pcap文件
- 24. 創建一個Microsoft.JScript文件
- 25. 創建一個.bat文件
- 26. 創建一個makefile文件
- 27. 創建一個php引導文件 - 無法訪問文件
- 28. PHP - 從一個對象創建一個XML文件
- 29. 如何創建一個鏈接來下載一個PHP文件?
- 30. 如何添加一個txt文件,並創建一個PHP ZIP
[''file_put_contents(「/ path/filename.txt」,「把這東西寫到文件...」);'](http://us3.php.net/manual/en/function。 file-put-contents.php) –
[我如何在服務器上創建文件?](http://stackoverflow.com/questions/5133999/how-do-i-create-file-on-server) –
另外http://stackoverflow.com/questions/9752904/write-to-create-file-in-php –