I want alter the URI's files before they are stocked in the server. The file insert, I mean, everywhere/time a file is uploaded via Drupal (all insert file process, not only when an user add a file via a form)

Is it possible ?

An example : With drupal defaults settings, files ares stocked in the files directory (drupal/sites/default/files)

I want stock files in another directory (out of drupal main directory, by exemple in the directory /save/files)


I want to organize files like this : files/pictures/01_May files/pictures/02_May ... files/pictures/day_month (its an exemple for pictures, maybe there is another structure for the video etc..)

So, when the user or the drupal code (.module, via the drupal api) upload a file to the server I want automatically stock this file in the directory /save/files) With the hook insert I can change the URI of the file, but during the hook insert the file is ulready uploaded in the server.

I'm looking for a way for move any files uploaded to the good directory before files are stocked in the server

  • I ran into a similar need some time ago, this might help you drupal.stackexchange.com/questions/118677/… The file is uploaded to a temporary directory on the form then moved to the permanent directory upon submit. You should be able to change the filename during the validation before it is written permanently. Apr 28 '16 at 20:17
  • Thanks for answer, but i'm looking for a way who the file comes directly to the target directory (not temp dir then final directory). Moreover, I want this new target directory get another files insert by user (files likes : css/jss compressed, files inserted via a custom module etc..) Apr 29 '16 at 9:47
  • I'm not sure I understand: do you want to change the directory where the files are stored? Is it just for the files from that form or for all files (a global setting)? Apr 29 '16 at 11:42
  • 1
    Thanks for the example. Does this tutorial might get you started. Basically, you have to: 1) hook into every file upload - you should be able to use hook_form_alter and add a validation to any file upload 2) then in your validation function overwrite the file name and upload path. May 2 '16 at 17:49
  • 1
    Yes, the file upload is only a Form API function. So AFAIK there is no way to universally manage ALL files no matter where they come from. May 3 '16 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.