I have the following code.
$main_image = glob('main*.{jpeg,gif,png,jpg,JPEG,JPG,PNG}', GLOB_BRACE);
if (count($main_image) != 1) {
die("Could not find main picture !");
$file_path = drupal_realpath($main_image[0]);
$file = (object) array(
'uid' => $userID,
'uri' => $file_path,
'filemime' => file_get_mimetype($file_path),
'display' => 1,
'filename' => $main_image[0],
);
$destination = "public://galerii_imagini/" . $file->filename;
if ($file = file_copy($file, $destination, FILE_EXISTS_REPLACE)) {}
else {
die("Could not copy " . $file_path . " in " . $destination);
}
}
In the Drupal logs, the error message is the following.
File ..../main_ROSE2106.JPG could not be copied, because the destination directory public://galerii_imagini is not configured correctly.
What should I do to configure it correctly?
In /admin/config/media/file-system I set the the path for public files (sites/default/files) and set the file permissions for that directory recursively to 777.
file_copy
and called by it functionfile_unmanaged_copy
in case of errors write messages to the system log. Did you look at the "Recent log messages" report? Most likely you will find answer there.../sites/default/files/galerii_imagini
?