Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » How are Image Gallery files renamed on upload?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1048 Views
  • scpi
    Avatar
    Community Member
    19 Posts

    How are Image Gallery files renamed on upload? Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: How are Image Gallery files renamed on upload? Link to this post

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

  • scpi
    Avatar
    Community Member
    19 Posts

    Re: How are Image Gallery files renamed on upload? Link to this post

    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);

    1048 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.