I have a working drupal batch process. In it I want to copy image files (JPGs) from a source directory into a target directory with PHP copy function. Both the directories exist. The source file does exist, too. But the copy does not succeed.
I checked for the file permissions of the source directory (0755) and the source file (0744) and the target directory (0755). The owner and group are that of the script.
I debugged by putting the success of the copy into watchdog. It says it was successfull. But the file is not there.
This is the code where the copy takes place
$copy_from = $_SERVER["DOCUMENT_ROOT"]."/".$file->filepath;
$copy_to = $_SERVER["DOCUMENT_ROOT"]."/".$path_new;
$success = false;
if (file_exists($copy_from)) {
$success = copy($copy_from, $copy_to);
watchdog('catalog_copy2', ($success ? 'yes' : 'no')
. ' | ' . "copy('{$copy_from}', '{$copy_to}')");
}
If I copy the watchdog output and edit it slightly to end up in an shell copy order
cp path/to/file dest_path
The file is copied with no fuzz at all. So no typos and no case sensitive issues are in order.
I’m clearly nearly out of my mind, because I do not understand why I cannot copy the files with PHP.
Strange thing though is, some of the files are copied with my batch and some are not.
I’d be grateful for any hint where to look for to find a solution.
edit
I’ve worked around the problem by using the shell cp command using php’s exec command. I’m not happy with this, but I had to make it work.
edit
I circumvented the problem by using the API function from the file_field module
the problem was not solved, but I managed to use the API functions from the file_field modules which works perfectly