Jump to:

23364 Posts in 18125 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Downloading uploaded files through "Files & Images"

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

Page: 1
Go to End
Author Topic: 601 Views
  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Downloading uploaded files through "Files & Images" Link to this post

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

  • MateuszU
    Avatar
    Community Member
    89 Posts

    Re: Downloading uploaded files through "Files & Images" Link to this post

    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.

  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Re: Downloading uploaded files through "Files & Images" Link to this post

    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!

  • MateuszU
    Avatar
    Community Member
    89 Posts

    Re: Downloading uploaded files through "Files & Images" Link to this post

    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 %>

  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Re: Downloading uploaded files through "Files & Images" Link to this post

    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!

    601 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.