Closed (fixed)
Project:
Node Images
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
12 Dec 2006 at 20:14 UTC
Updated:
4 Feb 2007 at 03:14 UTC
Jump to comment: Most recent file
I like this module but wanted an option to have drupal generate a filename, rather than use the user's uploaded filename.
I added the following code in node_images_admin_settings
$form['node_images_md5name'] = array(
'#type' => 'checkbox',
'#title'=> t('override file name'),
'#description' => t('Override uploaded filename with md5sum of file'),
'#default_value' => variable_get('node_images_md5name', false),
);
and patched the function _node_images_upload to
// Save uploaded image
$dest = _node_images_get_directory();
$filename = variable_get('node_images_md5name', false) ? md5_file($file->filepath."/".$file->name) : $file->filename;
if ($file = file_save_upload($file, $dest.'/'.$filename)) {
.
.
.
which allows me to have a configuration option to have drupal generate the filename for me. Instead of md5 other algorithms could be used, like timestamps or $_ENV[UNIQUE_ID] .
In case the same image is added again, the upload/file modules rename function applies and appends the counter to the filename.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | node_images.patch_1.txt | 3.51 KB | stefano73 |
Comments
Comment #1
stefano73 commentedThe attached patch against HEAD adds this feature. I made it a bit different from your suggestion, the hash is calculated on the destination file path and not on the temporary path, using the md5() function.
Comment #2
stefano73 commentedThis option and more in attached patch to http://drupal.org/node/106423#comment-175179
Comment #3
stefano73 commentedCommitted to HEAD.
Comment #4
stefano73 commented