When dealing with files using IMCE, interaction with the FILES table is made.
The information that is passed to the developer contains information of the file, but
not the ID of the file. So if you want to make any change of this file in the files table
you have to query to the path column, wich generates a very slow performance query.

Here is a simple patch to get this FID extra information to uploaded files.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

savioret’s picture

Version: master » 6.x-1.1
Issue tags: +file, +extra information, +fid
FileSize
3.89 KB

Here is the full patch, previous was not complete.

There is a problem, and it's that when you open the IMCE window and you have to load the current directory, you have to fetch the images information.
Thus, to get the FID of each file it should to query the files table using the path column... and that's exactly what we're trying to avoid... so in this case the FID is 0.

This patch is useful when you upload a file for first time. You have the FID, and you don't need to query to the path column.
In other cases, imce just works as always.
In my case, I just use IMCE to upload to a temporary folder, and the files are always new uploads.
With this modification, I have never to query the path column to get the file row of the files table, wich is not indexed.

Hope it helps to anybody.

ufku’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
Status: Patch (to be ported) » Needs review
FileSize
2.08 KB

Thanks for the patch. I've made one that does not require to patch template files. It introduces imce.urlId object that stores file paths(urls actually) with their ids, so we can grab the id using the file path.

dragon2000’s picture

your patch works correctly for the new uploaded file.
but it doesn't work for already existing files.

ufku’s picture

The patch does aim new inserted files. Other files are read from the file system(this is required to support ftp uploaded files) and it is not feasible to get their IDs by querying the database for each.

ufku’s picture

Status: Needs review » Fixed

This has been committed with an extra relpath property in the file object.
It is the rawurlencode'ed file path relative to the drupal file directory path.
This is how it can be used to get the real file path with file.relpath:

$filepath = file_directory_path() .'/'. rawurldecode($imce_relpath_variable);

This method does not require checking download method or clean urls and will give more accurate results than using file.url since file.url may contain double encoded characters such as & or #.

Caveat the resulting filepath may contain non-utf8 characters and will not match the path stored in the DB because the file names are read from the file system which may store names in its own locale.

Status: Fixed » Closed (fixed)
Issue tags: -file, -extra information, -fid

Automatically closed -- issue fixed for 2 weeks with no activity.