bug #11772 [Filesystem] Add FTP stream wrapper context option to enable overwrite (Damian Sromek)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11772).

Discussion
----------

[Filesystem] Add FTP stream wrapper context option to enable overwrite

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Without this change it's not possible to override a file on FTP by calling Filesystem::copy($originFile, $targetFile, true) as PHP/FTP server responds with error like:

fopen(ftp://...@ftp/file.txt): failed to open stream: Remote file already exists and overwrite context option not specified FTP server reports 213 166440 []

TODO: Write an integration tests? How? Use some real FTP server?

Commits
-------

c056a9c [Filesystem] Add FTP stream wrapper context option to enable overwrite (override)
This commit is contained in:
Fabien Potencier 2014-08-31 05:30:41 +02:00
commit bdb01a68d2
1 changed files with 2 additions and 1 deletions

View File

@ -50,7 +50,8 @@ class Filesystem
if ($doCopy) {
// https://bugs.php.net/bug.php?id=64634
$source = fopen($originFile, 'r');
$target = fopen($targetFile, 'w');
// Stream context created to allow files overwrite when using FTP stream wrapper - disabled by default
$target = fopen($targetFile, 'w', null, stream_context_create(array('ftp' => array('overwrite' => true))));
stream_copy_to_stream($source, $target);
fclose($source);
fclose($target);