Using Drupal 6.10, Image 6.1-1.x-dev (dated 2009-03-09), on Debian 'Lenny' install.

When creating a node of type Image, I'm able to preview the uploaded picture and its generated thumbnail. I can see the physical files in the temp dir (in my case, sites/default/files/images/temp)... while the Image page is still in its "preview" stage, e.g. I have not clicked "Save" yet.

When I click "Save", this is the error I receive:

"The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename."

I added instrumentation to includes/file.inc by adding to file_copy():

drupal_set_message("Copying '$source' to '$dest' ($replace)");

around line 221. With this in place, and repeating my action of creating an Image node type, I get the additional text:

* Copying 'sites/default/files/images/temp/image.jpg' to 'sites/default/files/images/image.jpg' (0)
* Copying 'sites/default/files/images/temp/image.thumbnail.jpg' to 'sites/default/files/images/image.thumbnail.jpg' (0)
* Copying 'sites/default/files/images/image.jpg' to 'sites/default/files/images/image.jpg' (0)
* Image Test image has been created.
"The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename."

Note that the original error is still in place. If I manually view the directory contents, it is empty. The images have *apparently* been copied out of sites/default/files/images/temp to the parent directory (sites/default/files/images), but this parent directory is empty. Something has happened to the files.

The permissions for the directory tree to sites/default/files/images and sites/default/files/images/temp are "fine" in that the webserver process can provably write to at least the temp dir, and given the temp dir has the same permissions and ownership as the parent dir, and also given that the Drupal 6.10 UI does not give an error/warning re: permissions...

I am hoping someone can assist me with at least further instrumenting the code to narrow down my problem, if not suggesting a straightforward solution.

Comments

julia_g’s picture

Same thing is happening to me. Did you manage to find any clues?

julia_g’s picture

OK, I've figured out the files are copied to the right directory but then get deleted in image_update in the following code:
if (!empty($node->new_file)) {
// The derivative images were built during image_prepare() or
// image_create_node_from() so all we need to do is remove all the old,
// existing images.

// Remove all the existing images.
$result = db_query("SELECT f.fid, f.filepath FROM {image} i INNER JOIN {files} f ON i.fid = f.fid WHERE i.nid = %d", $node->nid);
while ($file = db_fetch_object($result)) {
file_delete(file_create_path($file->filepath));
db_query("DELETE FROM {files} WHERE fid = %d", $file->fid);
}

I don't have time to dig further, maybe someone can look at the process of building derivative images and tell us what is wrong with this picture?

smoothify’s picture

I also have run into this problem with the latest dev version of image.

The strange thing is it just stopped working normally overnight without any module updates or filesystem changes.

I traced the code and the image:

  • gets uploaded to the temp folder,
  • has the derivative sizes built,
  • gets copied to the correct images folder.
  • image_update gets fired and because $node->new_file is still set then it deletes all the files from the images folder

I don't know where the problem lies, but to get it working I added the following line to image.module at around line 540. (after the foreach loop)

$node->new_file = FALSE;

so now the image_insert function ends up looking like this

function image_insert($node) {
  // Derivative images that aren't needed are set to the original file. Make
  // note of the current path before calling _image_insert() because if it's
  // in the temp directory it'll be moved. We'll need it later to determine
  // which derivative images need to be saved with _image_insert().
  $original_path = $node->images[IMAGE_ORIGINAL];

  // Save the original first so that it if it's moved the derivatives are
  // placed in the correct directory.
  _image_insert($node, IMAGE_ORIGINAL, $original_path);

  $sizes = image_get_derivative_sizes($node->images[IMAGE_ORIGINAL]);
  foreach ($sizes as $key => $size_info) {
    if (!empty($node->images[$key]) && $node->images[$key] != $original_path) {
      _image_insert($node, $key, $node->images[$key]);
    }
  }
  $node->new_file = FALSE;
}
lightlisha’s picture

I am getting this same message when trying to use image import-
"The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename."
After doing a search of the issue queue I found this thread. I also found an older thread which has a recent patch, which seems to be untested and not yet marked as needing review(?)
I am relatively new to drupal and have little idea what to do with this information. But, since no one else mentioned it on this thread, I thought it may help figure out the problem- #243895: ERROR: "The selected file ... could not be copied".

There is another bug report of the same type in the issue queue of the upload image module: #131597: The selected file could not be copied, because no file by that name exists..

I would not know which of these issues to mark as dupicate, they all have good information in them, and I don't know any code. Again, I hope this helps.

Rabeh’s picture

I get this issue as well. Files stay in temp and not copied elsewhere. Just get an image with an X through it on the actual website.

Have made all permissions 777, so its not a permissions issue.

nclavaud’s picture

Facing similar issue (using Drupal 6.20 + Image 6.x-1.1).

In my case, I am triggering Rules actions after an Image node has been created. One of these actions trigger a node update which calls image_update(). Since $node->new_file is still set to 1, the images get deleted and I get the error message mentionned above.

As a workaround, I triggered a custom Rule action that would set $node->new_file to NULL before updating the node, and it solved my problem.

xaviercas’s picture

Drupal 6.20
Image 6.x-1.1
Image Attach 6.x-1.1
Image Gallery 6.x-1.1
Image Gallery Management 6.x-1.0-beta6
Image Import 6.x-1.1

Getting similar problem here. Tried to upload by creating a new image node and get:'File upload error. Could not move uploaded file.'
or from folder with image import: 'The selected file path-to-image.jpg could not be copied.'
Permissions seem ok.