建立新檔案- $filename = "newfile.txt";
- $newContent = "新文件的內容";
- if (file_put_contents($filename, $newContent) !== false) {
- echo "新文件已建立.";
- } else {
- echo "建立失敗";
- }
複製代碼 刪除文件- $filename = "file_to_delete.txt";
- if (unlink($filename)) {
- echo "文件已刪除.";
- } else {
- echo "無法刪除文件.";
- }
複製代碼 重新命名檔案- $oldFilename = "old_name.txt";
- $newFilename = "new_name.txt";
- if (rename($oldFilename, $newFilename)) {
- echo "文件命名成功.";
- } else {
- echo "文件命名失敗.";
- }
複製代碼 |