Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

How are Image Gallery files renamed on upload?

Go to End

3 Posts   1679 Views


Community Member, 21 Posts

23 June 2010 at 8:53am

Edited: 23/06/2010 8:55am

I'm trying to figure out exactly how files are renamed when you upload them into an Image Gallery album. Spaces are replaced with hyphens, multiple hyphens are cleaned up, underscores are (sometimes) removed, and punctuation is removed. There might be other stuff going on too, but I'm not sure because I haven't been able to track down the exact functions responsible.

I need to be able to associate the original file name with the one that SilverStripe created on upload, so I really need to know exactly what's going on. Anybody have any ideas where to look? I thought I might have found it in sapphire/filesystem/File.php, function setName($name), but after trying it on some sample input, it seems that's not quite it.


Forum Moderator, 4102 Posts

23 June 2010 at 9:11am

I think it uses the same algorithm as SiteTree:generateURLSegment().. [a-zA-Z0-9\-], with spaces replaced with hyphens.


Community Member, 21 Posts

24 June 2010 at 4:23am

That wasn't quite it either. After some digging, I think I found it inside the load() function in sapphire/filesystem/Upload.php, starting on line 114:

// Generate default filename
$fileName = str_replace(' ', '-',$tmpFile['name']);
$fileName = ereg_replace('[^A-Za-z0-9+.-]+','',$fileName);
$fileName = ereg_replace('-+', '-',$fileName);
$fileName = basename($fileName);