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

UploadField path error


Reply

5 Posts   412 Views

Avatar
T3nD4n

3 June 2013 at 9:52am Community Member, 16 Posts

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!

Avatar
Bambii7

3 June 2013 at 7:28pm (Last edited: 3 June 2013 7:28pm), Community Member, 254 Posts

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;

Avatar
T3nD4n

4 June 2013 at 7:08am (Last edited: 4 June 2013 7:56am), Community Member, 16 Posts

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.

Avatar
Bambii7

4 June 2013 at 2:09pm Community Member, 254 Posts

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.

Avatar
T3nD4n

5 June 2013 at 5:11am Community Member, 16 Posts

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>