0

I have a Drupal site and I am unsure of how the files directory works.

It seems at the moment all files uploaded to the site go to the files directory. If I create a new node and upload fish.png which goes to the files directory another user also uploading a file called fish.png will overwrite my file.

Have I missed something here???

1
  • The file will not be replaced. The new one will be renamed to fish_1.png and so on. Commented Jun 29, 2012 at 22:14

2 Answers 2

1

You can see the how to set the file system settings on File system settings. You can also change it, and specify the other folder for the files as per your requirement.

0
0

If I create a new node and upload fish.png which goes to the files directory another user also uploading a file called fish.png will overwrite my file.

The file is renamed, and an number is added to make the filename unique. When an uploaded file is saved, file_save_upload() indirectly calls file_create_filename(), which contains the following code.

  if (file_exists($destination)) {
    // Destination file already exists, generate an alternative.
    $pos = strrpos($basename, '.');
    if ($pos !== FALSE) {
      $name = substr($basename, 0, $pos);
      $ext = substr($basename, $pos);
    }
    else {
      $name = $basename;
      $ext = '';
    }

    $counter = 0;
    do {
      $destination = $directory . $separator . $name . '_' . $counter++ . $ext;
    } while (file_exists($destination));
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.