API page: http://api.drupal.org/api/drupal/includes--file.inc/function/file_copy/7

Describe the problem you have found:

The documentation says, that you can ommit the $destination parameter, which I think means you can do file_copy($file); and thats it, but you get always (?) the error massage about not copieing the file and wrong use of file_copy(); As I understand default parameters in functions is that they are optional. I followed the stack inside file_copy where the first usage of $destination is: if (!file_valid_uri($destination)) and every functional call that is then comming does not *like* NULL as given parameter (for example one function does an explode on NULL then etc.)

So I think this is a wrong description of the destination parameter. There should be either a check if that parameter is_null() and therefore replace it with the default wrapper or I could use it with the NULL value as well .- which means all the inside called functions accept NULL.

Comments

jhodgdon’s picture

Title: Documentation problem with file_copy » file_copy doc says you can omit destination, but you can't
Version: 7.0 » 8.x-dev
Issue tags: +Needs backport to D7

I agree with this assessment. If you follow the code path for the $destination parameter, you will see that if it is empty, the function fails. The doc is wrong.

The doc should be fixed in D8 first, then ported to D7.

droplet’s picture

Component: documentation » file system

it's function never used in D7+ ??

check back D6 version, it will return public dir.
$dest = file_create_path($dest);
http://api.drupal.org/api/drupal/includes--file.inc/function/file_copy/6

it is a bug, not the api changes.

jhodgdon’s picture

Component: file system » documentation

To figure out whether the change was an intentional change or an API regression, we would need to find the issue where it was changed.

For now, I would assume it was an intentional change (since several things about the function changed), and that the documentation was not changed accordingly?

Let's see...
http://drupal.org/update/modules/6/7#unmanaged_files

So really, file_copy() in D6 became file_unmanaged_copy() in D7, and the new file_copy() does need a destination. I think it was intentional and we just need to fix the doc.

jhodgdon’s picture

Status: Active » Closed (duplicate)

I think the reason for this problem is that the drupal_realpath() doc is wrong, so I'm consolidating this issue with
#1191236: Correct file_copy, file_move, file_save_data, and drupal_realpath to match documentation and their unmanaged counterparts.