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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Downloading uploaded files through "Files & Images"


5 Posts   626 Views


20 January 2010 at 2:12pm Community Member, 80 Posts

Sorry if this is a stupid question.

I created a form on my site for folks to upload bio information and also upload their photo. I used "userforms" to do this. The problem is that the photo they upload doesnt get passed through the email i tell it to go to. In the Files and Images section in the CMS, i can see the uploaded images. But cant download them. I want my client to be able to go in their and download them to their computer. Is there are a way to do this? I tried the edit option, but the image doesnt show.

HELP!! :)


20 January 2010 at 2:50pm Community Member, 89 Posts

Well what are you passing to your users in the email? If that's only a link, all the files from Files & Images section are stored in the asset directory which is directly accessible via your browser. It's just the matter of passing the right link. You can get the proper link by grabbing the File object and doing ->Link() on it. Can you paste the template you are using for the emails?



20 January 2010 at 3:24pm Community Member, 80 Posts


Thanks for replying.

I figured out that the file size issue passing via email was due to the userdefinedform.php file setting a 1mg restriction. I changed this code in the file:

// Attach the file if its less than 1MB, provide a link if its over.
                  if($file->getAbsoluteSize() < 1024*1024*1){
                     $attachments[] = $file;

I am still curious how to display on a webpage all files listed in a particular folder in Files and Images.

I dont know what to add to the php code for that page type to get the data from the table. Any ideas? Hopefulyl I am being clear, I am sorry if not, I am not the most highly php savvy individual!


20 January 2010 at 3:36pm Community Member, 89 Posts

This should get you through, just note it might contain errors, didn't actually coded that in:

This code would be placed in your Page class. It fetches all the images which are direct children of given folder:

function FilesToDisplay() {
$dir = DataObject::get_one('Folder', "Filename='your/directory/name/'");
if ( $dir ) {
return DataObject::get('Image', "ParentID='$dir->ID'");

return null;

And this code goes into template. It iterates over the DataObjectSet returned by FilesToDisplay and renders the resulting objects as <img... tag. This will work provided all the objects in the set are of class Image, which they should, cause we did DataObject::get looking for 'Image' objects.

<% control FilesToDisplay %>
<% end_control %>


20 January 2010 at 4:04pm Community Member, 80 Posts

I havent figured out how to send virtual beers to people in this awesome community, but when I do, it will be Dos Equis!

Thanks so much!