This is an example of how to allow fopen() to overwrite a file on an FTP site. If the stream context is not modified, an error will occur: "...failed to open stream: Remote file already exists and overwrite context option not specified...".
<?php
// The path to the FTP file, including login arguments
$ftp_path = 'ftp://username:password@example.com/example.txt';
// Allows overwriting of existing files on the remote FTP server
$stream_options = array('ftp' => array('overwrite' => true));
// Creates a stream context resource with the defined options
$stream_context = stream_context_create($stream_options);
// Opens the file for writing and truncates it to zero length
if ($fh = fopen($ftp_path, 'w', 0, $stream_context))
{
// Writes contents to the file
fputs($fh, 'example contents');
// Closes the file handle
fclose($fh);
}
else
{
die('Could not open file.');
}
?>
گزینههای متن FTP
گزینههای متن FTP — فهرست گزینههای متن FTP
Description
گزینههای متن برای ftp:// و ftps://.
Changelog
| Version | Description |
|---|---|
| 5.1.0 | proxy اضافه شد. |
| 5.0.0 | overwrite و resume_pos اضافه شد. |
Notes
Note: گزینههای متن جریان سوکت زیرین
گزینههای بیشتر متن پشتیبانی شده در انتقال زیرین برای جریانهای ftp:// به گزینههای انتقال tcp:// مراجعه کنید. برای جریانهای ftps:// به گزینههای متن برای انتقال ssl:// مراجعه کنید.
php dot net at misterchucker dot com ¶
4 years ago
