Search code examples
phpfiledrupal-6file-copying

drupal file_check_path return false


I am working on files in drupal. i use local wamp server with drupal6.
my drupal path is localhost/drupal6 .i have a file in this path <drupal root >\files\images\111.jpg .

$image='/drupal6/files/images/111.jpg';

I want copy(or move) this file to another sub folder in this path but give me error in php copy($image,'anotherdestination') or drupal_copy($image,'anotherdestination',FILE_EXISTS_RENAME).

when i use var_dump(file_check_path($image)); it return me false . the files and iamges folder have all permission for any user in windows. where is the problem?

notice: i wrote all of this code in a function in a custom module with path sites/all/module/mymodule/mymodule.module


Solution

  • There's a difference between how files are accessed over HTTP and via the file system. Over web /drupal6/files/images/111.jpg is perfectly fine, since it'll be evaluated as http://example.com/drupal6/files/images/111.jpg. But I bet you do not have a drupal6 directory in the root of your file system.

    You probably want something like this.

    copy('c:\drupal6\files\images\111.jpg', 'c:\drupal6\files\other_images\111.jpg');
    

    I'm not entirely sure about paths in Windows but I think that should be correct.