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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Downloading uploaded files through "Files & Images"


Go to End


5 Posts   1144 Views

Avatar
Hello_electro

Community Member, 80 Posts

20 January 2010 at 2:12pm

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!! :)

Avatar
MateuszU

Community Member, 89 Posts

20 January 2010 at 2:50pm

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?

m.

Avatar
Hello_electro

Community Member, 80 Posts

20 January 2010 at 3:24pm

Mateuzs:

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!

Avatar
MateuszU

Community Member, 89 Posts

20 January 2010 at 3:36pm

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 %>
$Tag
<% end_control %>

Avatar
Hello_electro

Community Member, 80 Posts

20 January 2010 at 4:04pm

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!