我試圖在PHP中將數據寫入一個簡單的txt文件,然後打開它,以便用戶可以下載它。我想保持它非常輕巧,當我運行此我得到:
PHP中的輕量級fopen技術
Warning: fopen(testFile.txt) [function.fopen]: failed to open stream: File exists in /home/user/script.php on line 9
這裏是我的示例代碼:
<?php
$File = "sample.txt";
$write = fopen($File, 'w') or die();
$stringData = "asdfjkl;";
fwrite($write, $stringData);
fclose($write);
$open = fopen($File, 'x') or die();
fclose($open);
?>
謝謝!
關於['fopen'](http://www.php.net/manual/en/function.fopen.php)的文檔。 **模式x **:如果文件已經存在,則fopen()調用將返回FALSE並生成E_WARNING級別的錯誤。 – 2012-01-03 22:31:46
雖然我似乎無法找到該文件。 – user1062058 2012-01-03 22:40:33