21278 Posts in 5728 Topics by 2599 members
General Questions
SilverStripe Forums » General Questions » [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 2535 Views |
-
[SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

16 July 2012 at 6:10am Last edited: 16 July 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
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

18 July 2012 at 11:41pm Last edited: 18 July 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...
http://api.silverstripe.org/3.0/framework/forms/UploadField.html -
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

19 July 2012 at 10:22am Last edited: 19 July 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
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

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=allthen logout and login again.
read http://www.silverstripe.org/general-questions/show/20246 for more details.
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

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.
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

24 July 2012 at 9:49am
Set upload directory in the SS3
$f = new UploadField('Images', 'Images');
$f->setFolderName($folder); -
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

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.
-
Re: [SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width

25 July 2012 at 12:22am Last edited: 25 July 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?
| 2535 Views | ||
| Go to Top | Next > |




