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);
?>

更新於: 21-09-2020

357 次瀏覽

開啟你的職業生涯

完成課程取得認證

開始
廣告