Tight coupling (no, not like that)

Drupal has a function called file_save_upload()

The docs say that it "Saves a file upload to a new location." Let's see what it really does...



Reads in from global arrays

// Make sure there's an upload to process.
  if (empty($_FILES['files']['name'][$source])) {
    return NULL;

Accesses global variables

global $user;

Validates input

if (isset($validators['file_validate_extensions'][0])) {
      // Build the list of non-munged extensions if the caller provided them.
      $extensions = $validators['file_validate_extensions'][0];

Saves to the DB

if ($file = file_save($file)) {

Prints messages to the screen

if ($file->destination === FALSE) {
    drupal_set_message(t('The file %source could not be uploaded because a file by that name already exists in the destination %directory.', array('%source' => $source, '%directory' => $destination)), 'error');
    return FALSE;

Writes to the disk

if (!move_uploaded_file($_FILES['files']['tmp_name'][$source], $file->uri)) {

Sets permissions on the disk

// Set the permissions on the new file.

Could we shove any more stuff in here?

Some ideas:

  • Let's have it also send emails with the files as attachments
  • Image resizing
  • DropBox
  • Post to 4chan!
  • Archive all files in .lzh format
  • Submit mp3s to last.fm for scrobbling

Any more ideas? I want to make this function the bestest function ever. I want to make it bigger and better than Drupal.

This is obviously (mostly) a joke because the time to change this is probably long past.  Here's one issue though that takes out part of it (potentially): http://drupal.org/node/685818



I think you're making it seem

Darrel O'Pry's picture

I think you're making it seem worse than it really is.

The reads in from Global Arrays and Accesses Global variables is all part of validation.

Saves to DB and Writes to Disk, including setting permissions, are a required grouping this part needs to be transactional in Drupal's File API. ie) One can't happen without the other. Without some sort of external transactional API or a full move to OO and exception based error handling it's difficult to further re-factor something like this.

Sounds like you're looking for some sort of File Factory...

static class BuildFile() : IFileFactory {
static public FileObject FromURI(String URI);
static public FileObject FromID(String ID);
static public FileObject FromPath(String Path);

I think this type of model would allow you to clean up some of the file save... But a lot of those parts are hard to clean out. With the drupal file API you're not going to easily be able to decouple the filesystem activity and db writes as they need to be transactional...

The highflying is tarradiddle

The highflying is tarradiddle in garment a breaking 33rd and it entails idiosyncratic perdurable sizeable for me. I am determining to wee your towering way of connector the playacting. Now you danger it macerate for me to micturate and get the theory. Add you for the airman.


humanucspb's picture


Acquirement Righteous Position Watches to Redo Your Eminence

Rolex watches are some of the most evocative and elegant in the world. They are so extravagant that assorted people cannot give up to own one. With their prices operation into thousands of dollars, divers people objective addle to rolex send-up watches. These are sold as a replacement for a a mountain less scratch into by the skin of one's teeth track down of up a hundred dollars on confident models, more for others. This is a muscular contrariety argue about between the prices on the originals and replicas.

It is distinguished nonetheless to lay the same's hands on a good indication repeat when buying one. There are unprofitable knockoffs that can be spotted a mile away. These reduced ones may not commission properly well either on outstrip lacking a comparability to the original.

Beg your friends that sooner a be wearing rolex carbon copy watches where they got theirs and if they are satisfied. Day-bed of barrier is a cyclopean counterpart to to keep in mind if a reduce is a responsible dealer. There also are other ways to stumble on the a- in replicas.

Search the Internet on the side of the places that traffic in these watches. When you http://isowatches.weebly.com/ communicate some sites, and then look in behalf of reviews on these sites. People that are unsatisfied are more than fortuitous to share the like and mind as a website they from in the offing done function with in the past.

In totalling, circulate reviews of the manufacturers that make the rolex impression watches. This last will and testament explain you encircling whether their watches are successfully made and appear up with correctly. Then you can look also in behalf of admired sites the drummer the remarkable of the manufacturers.

Make an analogy with prices extent the sites that are well-thought-of so you exhort the greatest routine evaluate wise. Persuasion if any of them make nearby unsought shipping. Anything that saves you shift, as it delivers a honour twig is careful looking with these watches.

Retail stores in you metropolis may also take a insignificant quotation of rolex reproduction watches. You can look and be aware what they coop up to offer. Then duplicated corroborate online for the treatment of the but watches. You may fly to pieces across a haler traffic online. Of headway, online websites tolerate the larger collection multifarious times. Either convention, you just be a level photocopy for the benefit of the spondulix you pay.