Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

PHP FTP context options

Giới thiệu

Tùy chọn ngữ cảnh cho ftp:// và ftps://:

overwriteCho phép ghi đè file đã tồn tại trên server từ xa khi tải lên.
resume_posVị trí offset file bắt đầu truyền. Chỉ áp dụng tải xuống. Mặc định 0 (đầu file).
proxyProxy yêu cầu FTP qua HTTP proxy. Chỉ áp dụng đọc file. Ví dụ: tcp://squid.example.com:8000.

Ví dụ cho phép fopen() ghi đè file trên FTP:

Ví dụ

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