Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » UploadField path error

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: 402 Views
  • T3nD4n
    Avatar
    Community Member
    16 Posts

    UploadField path error Link to this post

    hi all.
    the error is that the uploadfield is saving the file in the rigth folder (temas), i check and the file is saved ok. but when in the template I link the file with $link or $URL the path is wrong, is like was saved to the folder assets/ and not to the folder assets/temas.

    here the code.

    class Musica extends Page {

       static $db = array(
       );

       static $has_many = array(
          'Canciones' => 'File'
       );

       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $canciones = new UploadField('Canciones');
          $canciones->getValidator()->allowedExtensions = array('mp3', 'wav');
          $fields->addFieldToTab("Root.Canciones", $canciones);
          $canciones->setFolderName('temas');
          return $fields;
       }
    }
    class Musica_Controller extends Page_Controller {
    }

    // and in the template

    <% control $Canciones %>
       <div >
          $Link- $URL//both throw the path to the file in the folder assetst/
       </div>

    <% end_control %>

    is like the record saved at the file table in the db is not taking care the folder that was saved the file.

    can any body help me?

    the version of SS is 3.0.5.

    Bye!

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: UploadField path error Link to this post

    Hi again,

    I'm not 100% why this isn't working, but you could try $AbsoluteURL and make sure you ?flush=all
    Also double check in the DB, making sure the correct path is saved in there

    SELECT id,filename FROM ssdb.File ORDER BY id DESC;

  • T3nD4n
    Avatar
    Community Member
    16 Posts

    Re: UploadField path error Link to this post

    hi again Bambii7 seems I'm the only with this problem :S.

    the $AbsoluteURL returns an incorrect path to the file too.

    I check the table File in the DB and the UploadField is saving the file with the incorrect path, but the file is saved in the correct folder

    example if I upload a file called song.mp3.

    the file is saved at the folder: assests/temas/song.mp3 but the record filename in the db is assests/song.mp3.

    ignores the folder where the file was saved.

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: UploadField path error Link to this post

    Umm lastly what are the permissions of the assets folder and an example uploaded image, it is possible they're able to write but unable to read the file.

  • T3nD4n
    Avatar
    Community Member
    16 Posts

    Re: UploadField path error Link to this post

    Hi bambii7 the permissions of the assets folder and the assets/temas are 755
    the permissions on an example uploaded file to the assets/temas are 644.

    The fix that Im using is to manually set the path to the file in the template.

    <a href="assets/temas/$Name">$title</a>

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