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

Specify Upload Directory (Image and File)


Reply

2 Posts   1623 Views

Avatar
Ryoken

22 April 2010 at 12:08pm Community Member, 18 Posts

So I'm trying to upload images and files to specific directories ( It's a large site, just having everything into the uploads directory would be a mess in no time, and you can't be expected to upload files first then link after ), and I've having no luck..

http://pastie.org/928363

That's my code. It's my understanding that there's a problem on the most basic level. I even tried the 2.4RC version of Upload.php with no luck.

Does anyone have a fix ? Either a custom class or fix for the current one ?

I remember trying to do the same thing with swfupload a while back and had no luck with that either, though I haven't tried this time as they are only images, but if it works now does anyone have a functional example of that ?

Thanks

Avatar
Gelert

23 March 2011 at 3:25am Community Member, 8 Posts

The correct code to fix this problem is:

$fields->addFieldToTab("Root.Content.Main", new ImageField('HomePagePhoto', 'Home Page Image (upload 600px width image, it will be resized properly)',NULL,NULL,NULL,'HomePagePhotos'), 'Content');

Where 'HomePagePhotos' is a directory inside assets. The path is relative to assets.