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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Specify Upload Directory (Image and File)


Go to End


2 Posts   3576 Views

Avatar
Ryoken

Community Member, 18 Posts

22 April 2010 at 12:08pm

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

Community Member, 14 Posts

23 March 2011 at 3:25am

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.