PHP FTP上下文选项

介绍

下面列出了 http://https://传输的上下文选项-

覆写 仅允许上传时覆盖远程服务器上已经存在的文件。
resume_pos 开始传输的文件偏移量。仅适用于下载。默认为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);
?>