9 years ago
3
Topic

I added these to the upload_image.php so that images rename on upload.

//Random Number

$rand = rand(100000, 999999);

//Date-time
$ndate = date('YmdHis');

//File Extension
$file_ext = ( strrpos( $userfile['name'], '.' ) ) ? substr( $userfile['name'], strrpos( $userfile['name'], '.' ) + 1 ) : '';

//Actual name for image
$userfile['name'] = $ndate.'_'.strval($rand) . "." . $file_ext;

It works great except that if you save an old content it deletes all the old images that were uploaded before the addition.

Any suggestions?

Get a Book for SEBLOD
9 years ago
0
Level 1

Just a follow up. I noticed it does that when you have a fieldx for a gallery and not on the main image.

9 years ago
0
Level 1

Hey guys my bad was doin the renaming in the wrong place. I'll just post my hack in case anyone needs something similar.

In plugins/cck_field/upload_image/upload_image.php around 400-500 line:

After: 

$ImageCustomName = $userfile['name'];

Add:

$rand = rand(100000, 999999);
$ndate = date('YmdHis');
$file_ext = ( strrpos( $ImageCustomName, '.' ) ) ? substr( $ImageCustomName, strrpos( $ImageCustomName, '.' ) + 1 ) : '';
$ImageCustomName = $ndate.'_'.strval($rand) . "." . $file_ext;

So the result will be on each uploaded image the name will change to something like this: 20140702105640_272184.jpg

It has date time and a random number. This way you will never have issues with duplicate image names ;)

51 Posts
ilga
8 years ago
0
Level 1

Hi seblod team, can we use that solution? If we update seblod version, do we have make the same hack again?

Get a Book for SEBLOD