2015-04-17 71 views
1

我使用上面的代碼在文件中寫入:如何使用stream aws s3 php在文件末尾寫入?

require 'vendor/autoload.php'; 
use Aws\S3\S3Client; 
use Aws\S3\Exception\S3Exception; 

$client = S3Client::factory(array(
    'credentials' => array(
     'key' => 'key', 
     'secret' => 'secret', 
    ) 
)); 
$client->registerStreamWrapper(); 
$stream = fopen("s3://bucket-name/files/filename.txt", 'w'); 
fwrite($stream, $message); 
fclose($stream); 

它的工作原理,但我需要的文件保存內容的末尾寫已經所著...我想用'W + '是解決方案,但諾伊, PLZ我該怎麼做?

謝謝。

+0

根據文檔,你應該使用'a'。 http://php.net/manual/en/function.fopen.php –

+0

謝謝,好吧,我會嘗試一下。 – user3911183

+0

當然,只是更新我,如果它幫助 –

回答

0

根據php手冊(fopen):

模式W¯¯

寫入方式打開;將文件指針放置在文件的開頭 處,並將該文件截斷爲零長度。如果該文件不存在 ,請嘗試創建它。

所以,如果你想開始在文件末尾寫, 你應該使用模式一個

僅供寫作;將文件指針放在文件的末尾。 如果文件不存在,請嘗試創建它。