PHP FTP context options

PHPServer Side ProgrammingProgramming

Introduction

Context options for http:// and https:// transports are listed below −

overwriteAllow overwriting of already existing files on remote server while uploading only.
resume_posFile offset at which to begin transfer. Applies for downloading only.Defaults to 0 (Beginning of File).
proxyProxy FTP request via http proxy server. Applies to file read operations only. Ex −tcp://squid.example.com:8000.

This example shows how to allow fopen() to overwrite a file on an FTP site.

Example

<?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);
?>
raja
Published on 21-Sep-2020 09:13:52
Advertisements