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

[SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width


Go to End
Reply


35 Posts   5725 Views

Avatar
Craftnet

Community Member, 58 Posts

16 July 2012 at 6:10am

Edited: 16/07/2012 6:18am

Hi,
How to upload many files/images in one time.
In 2.4 i add UploadImages
In 3.0 i not idea how did this.

Now i build in gridfiles but to one entries i can attach one image :(

Someone can help?

EDIT

In ss3.demo i found like this "HasManyFilesUploadField" but i don't have idea how use it

Sorry for my bad English

Avatar
colymba

Community Member, 26 Posts

18 July 2012 at 11:41pm

Edited: 18/07/2012 11:42pm

the new UploadField does this for you.
If you have your relation set up on like this:

public static $has_many = array(
   'Images' => 'Image'
);

You can call UploadField and pass it the SS_List as argument:

$f = new UploadField('Images', 'Some images', $this->Images());
$fields->addFieldToTab('Root.Main', $f);

You can add some config to UploadField via setConfig to limit the number of file, the type and files and so on...
[url]http://api.silverstripe.org/3.0/framework/forms/UploadField.html[/url]

Avatar
Craftnet

Community Member, 58 Posts

19 July 2012 at 10:22am

Edited: 19/07/2012 10:25am

Thx for replay - it's workig - almost.

I do like you said.

Now I have like this:

Gallery.php

<?php
class Gallery extends DataObject
{
static $db = array (

);

static $has_one = array (
'Attachment' => 'Image',
'AsortymentyPage' => 'AsortymentPage'
);
   
   static $belongs_many_many = array(
);
   
   public static $summary_fields = array(
      
   );
   
   
   function getCMSFields() {
return new FieldSet(
new UploadField('Attachment')
);
}
}

AsortymentPage.php

...
static $has_many = array (
   'Images' => 'Image'
);
...
public function getCMSFields() {
   $fields = parent::getCMSFields();
$f = new UploadField('Images', 'Zdjęcia', $this->Images());
   $fields->addFieldToTab('Root.Galeria', $f);
      
return $fields;
}
...

And i Backend and frontend like this (attach)

I think I made a mess in static has_many and has_one :)

When I give code:

static $has_many = array (
   'Images' => 'Gallery'
);

I have error.

Sorry for my bad English

Attached Files
Avatar
Hattori

Community Member, 20 Posts

22 July 2012 at 8:10am

AsortymentPage.php

change

static $has_many = array(
   'Images' => 'Image'
);

to

static $many_many = array(
   'Images' => 'Image'
);

then run:
/dev/build?flush=all
/admin/pages?flush=all

then logout and login again.

read http://www.silverstripe.org/general-questions/show/20246 for more details.

Avatar
Liam

Community Member, 470 Posts

24 July 2012 at 6:31am

Might have missed it as I looked through the api docs, but is there a way to set the upload directory?

Any example working code would be great. I'm adding multiple images like in this thread.

Avatar
Hattori

Community Member, 20 Posts

24 July 2012 at 9:49am

Set upload directory in the SS3

$f = new UploadField('Images', 'Images');
$f->setFolderName($folder);

Avatar
Liam

Community Member, 470 Posts

24 July 2012 at 12:27pm

Perfect. Thanks.

One last thing as this is my first time working with SS3 and the UploadField.

After I have uploaded images, I can't edit or remove them from the page as seen here. http://shiftideas.com/uploads/ss-images_2f62.png

Is this normal or a bug? Using many_many relationship.

Sorry to hijack the thread.

Avatar
colymba

Community Member, 26 Posts

25 July 2012 at 12:22am

Edited: 25/07/2012 12:22am

to me this looks like a bug, I seen the same on my tests. The image file doesn't seem to be saved automatically in the right folder.
will probably need to investigates this a bit more. Maybe try the latest build on GitHub and see if it has been fixed?

Go to Top