Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Uploading a pdf or some kind of non image file

Our old forums are still available as a read-only archive.

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

Page: 1 2
Go to End
Author Topic: 6588 Views
  • meloniasty
    Avatar
    Community Member
    1 Post

    Uploading a pdf or some kind of non image file Link to this post

    Hi,

    I've added two file fileds in cms to add some non image files. I've doing this twice:
    1.
    $fields->addFieldToTab("Root.Content.Files", new FileField('File'));

    but there is no 'upload' button and i'dont know what i'm doing wrong

    next
    2.
    $fields->addFieldToTab("Root.Content.Files", new FileIFrameField('File'));

    and also there is no 'upload' button but is 'attach..' from uploaded files and i attached but cms interpreted me my pdf file like image, hmmm is this correct

    please give me some advice how to upload non image files

    and is there any method to upload multi files in cms (in content section - has_many?? )?

  • DesignCity
    Avatar
    38 Posts

    Re: Uploading a pdf or some kind of non image file Link to this post

    Hi Guys,

    I'm looking at doing something similar to the above (at least I think it is - had a trouble understanding the above post...). The information on Tutorial 2 - Creating a Staff section seems to be exactly what I'm looking for - except instead of Images, upload and attach a PDF (or any file, really...)

    From playing around with the files in that tutorial, it looks like:

    class StaffPage extends Page {
       static $db = array(
       );
       static $has_one = array(
    'Photo' => 'Image'
       );


    The 'Image' part is the bit that actually references the image upload box, changing this to anything else seems to remove the image upload box and functionality.

    Is there a way to simply enable upload of other files or is that a complex task? If it is relatively easy (for someone with limited knowledge) to do, can someone point me in the right direction of where and/or how this might be accomplished? I can only but try

  • DesignCity
    Avatar
    38 Posts

    Re: Uploading a pdf or some kind of non image file Link to this post

    Okay, I've figured something out that works for uploading files. Here are my files for anyone that's interested:

    ArticlePage.php (mysite/code/)

    <?php

    /**
    * Defines the ArticlePage page type
    */
    class ArticlePage extends Page {
       static $db = array(
          'Date' => 'Date'
       );
       static $has_one = array(
    'file_upload' => 'File'
       );

       static $icon = "mysite/images/treeicons/news";
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
          $fields->addFieldToTab("Root.Content.PDF", new FileIFrameField('file_upload', 'Upload and Attach Document'));
          
          return $fields;
       }
    }

    class ArticlePage_Controller extends Page_Controller {

    }

    ?>

    This creates a new tab in the CMS called "PDF" (as that's what the client will be uploading, but could be anything else) and gives you a box to upload a file or select one from the assets folder. It also provides a textbox for a caption.

    I call it on my template page as follows:

    ArticlePage.ss (mysite/templates/Layout/)

       <div id="extra">
    <% if file_upload %>
          <div class="extra_box">
             <h2>Download PDF</h2>
             <p>This announcement is available to download as an $file_upload.FileType:</p>
             <p><a target="_blank" href="$file_upload.URL">
             <strong><img src="$file_upload.Icon" alt="$file_upload.FileType" />&nbsp;&nbsp;$file_upload.Title</strong> ($file_upload.getSize)</a></p>
             <p><a href="http://www.adobe.com/products/acrobat/readstep2.html">Download the free PDF viewier <em>Adobe Reader</em> here</a></p>
          </div>
    <% end_if %>
       </div>

    The template checks to see if there is a file uploaded first, otherwise doesn't display anything. The following variables are used:

    $file_upload.URL - displays the relative url
    $file_upload.Icon - displays the icon for the file type (can be edited from /saphire/filesystem/File.php - about line 519)
    $file_upload.FileType - displays the name for the file type (in this case "Adobe Acrobat file", editable in the same file as above)
    $file_upload.getSize - displays the size of the file in a clean format ("32 KB, 1.3 MB" etc.)
    $file_upload.Title - displays the filename

    This is just a way I found out to do what I was looking for - if anyone has a better way or even the 'right' way, please let me know

  • pga
    Avatar
    Community Member
    8 Posts

    Re: Uploading a pdf or some kind of non image file Link to this post

    Why this example is not in documentation?
    Generally documentation of SilverStripe (mainly navigation way) is messy and very
    difficult to use.

  • ylluminate
    Avatar
    Community Member
    24 Posts

    Re: Uploading a pdf or some kind of non image file Link to this post

    I agree pga. We really need to see a regrouping on the documentation efforts for SilverStripe. Without a more involved community and stronger documentation, SS can never reach the levels of utilization that it deserves. It really worries me. While SS is about the best CMS on the market for many CMS needs (Drupal only does better in a choice few scenarios) it needs a refocussing of effort from the developers on documentation and really giving us the tools we need to find answers handily. IRC doesn't help a lot when you're on a different time zone, etc.

    Perhaps I should also qualify this a bit further: we need a recipe collection for SS. We need to have a central repository of specific things that could be useful and get some real contribution going in that direction.

  • DesignCity
    Avatar
    38 Posts

    Re: Uploading a pdf or some kind of non image file Link to this post

    Some good points here pga and ylon. If you have any specific ideas of how you would improve the current system, probably best you start a topic at http://groups.google.com/group/silverstripe-dev?hl=en, the developers group discussion. I'm sure the SS staff would be very happy for the input. Posting here under "Uploading a pdf or some kind of non image file" is probably not going to get noticed.

    The reason the code snippet isn't in the documentation is because I'm not a developer and while I created a working example, I'm not sure if this is the 'correct' way to create a file upload box. Putting something up on the wiki that is half right could confuse more than help.

    DC

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Uploading a pdf or some kind of non image file Link to this post

    DesignCity - example looks fine to me. If you make a wiki page with this example and a bit of a introduction, talk that would sure be helpful for users!

    One of the great things about the new Comments is that if the documentation is wrong, or is not the best way of doing things people can leave those remarks.. we can always refactor and or delete the page / information.

  • cerelac
    Avatar
    Community Member
    34 Posts

    Re: Uploading a pdf or some kind of non image file Link to this post

    Hi

    I have a problem with files attachment. I've already added the "attach file" field, but now i don't know how can I send this file as a attach in the email.

    Any ideas to solve this?

    Best regards

    6588 Views
Page: 1 2
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.