PHP FTP 上下文選項
引言
http:// 和 https:// 傳輸的上下文選項如下 −
覆蓋 | 在僅上傳時,允許覆蓋遠端伺服器上已有的檔案。 |
恢復位置 | 傳輸開始時的檔案偏移量。僅適用於下載。預設為 0(檔案開頭)。 |
代理 | 透過 http 代理伺服器代理 FTP 請求。僅適用於檔案讀取操作。例如 tcp://squid.example.com:8000。 |
本示例演示如何允許fopen()覆蓋 FTP 站點上的檔案。
示例
<?php $ftp_path = 'ftp://username:password@example.com/example.txt'; $stream_options = array('ftp' => array('overwrite' => true)); $stream_context = stream_context_create($stream_options); $fh = fopen($ftp_path, 'w', 0, $stream_context); fputs($fh, 'Hello World'); fclose($fh); ?>
廣告