7939 Posts in 1472 Topics by 944 members
|Go to End|
23 June 2010 at 8:53am Last edited: 23 June 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.
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.
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);
|Go to Top|