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.

CommentFileSizeAuthor
#1 node_images.patch_1.txt3.51 KBstefano73

Comments

stefano73’s picture

Status: Active » Needs review
StatusFileSize
new3.51 KB

The 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.

stefano73’s picture

This option and more in attached patch to http://drupal.org/node/106423#comment-175179

stefano73’s picture

Committed to HEAD.

stefano73’s picture

Status: Needs review » Closed (fixed)