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.

Customising the CMS /

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

Uploaded File Management on a Page


Go to End


5 Posts   1338 Views

Avatar
Parker1090

Community Member, 46 Posts

26 April 2013 at 1:44am

Hello!

I've got the front page of a site showing a slideshow, which uses images selected by the user through the CMS.

The code added to the back end is as follows:

class HomePage extends Page {
	static $many_many = array (
		'FrontImages' => 'Image'
	);
	
	static $allowed_children = '';
	
	public function getCMSFields() {
        $fields = parent::getCMSFields();
        
		$f = new UploadField('FrontImages', 'Front Images (Maximum of 10 images. Allowed files: .jpg, .jpeg, .png or .gif)', $this->FrontImages()); 
		$f	->setConfig('allowedMaxFileNumber', 10)
			->setFolderName('images/frontpage/')
			->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
		$fields->addFieldToTab('Root.Images', $f);
         
        return $fields;
    }
	
}

This loads the boxes fine. However (as shown in the screenshot), there's no remove or delete buttons for the already uploaded images. Any help would be appreciated :)

Thanks in advance!

Attached Files
Avatar
b00mtastik

Community Member, 18 Posts

29 April 2013 at 11:05am

Edited: 29/04/2013 11:07am

Hello,

Where are the images being uploaded to? Have you checked your asset folder under the "Files" menu item on the left hand side?

It could be that Silverstripe sees that directory and you can control that directory from the File manager and you can delete, change, and add more files in/from there?

If that doesn't work then you may have to code those features into this custom page?

I'm still learning quite a lot, but what I've said above is just an idea to check out.

-b00mer

UPDATE/EDIT:
It just clicked to me that the file manager would only pick it up if your images folder you created to keep those images, might only show up if they are inside the assets folder? If not then you definitely might have to code those features in (delete, edit etc), something I'd be interested in in the future as well.

Avatar
Cleon

Community Member, 1 Post

7 May 2013 at 5:27pm

Hi,

I have the same issue, were you able to find a solution?

Avatar
Parker1090

Community Member, 46 Posts

18 June 2013 at 8:56am

Hi,
Sorry for the very long delay (shows how often I check back).

I never found a solution, but would love to know one!

The images are uploaded to Assets/Images (as defined in the code), but the images on the front page itself are pulled through using the following:

<div id="slideshow">
	<ul id="carousel">
	<% loop $FrontImages %>
		<li>$croppedImage(930,300)</li>
	<% end_loop %>
	</ul>
</div>

The code in my first post has not changed.

Cheers,
Matt

Avatar
Parker1090

Community Member, 46 Posts

6 July 2013 at 1:09am

Edited: 06/07/2013 1:10am

I know this topic's a bit old, but I just thought I'd post a solution (finally).

In my first post, I had the following code:

 $f = new UploadField('FrontImages', 'Front Images (Maximum of 10 images. Allowed files: .jpg, .jpeg, .png or .gif)', $this->FrontImages()); 

However, the issue was the linking. Simply remove the red part as it seems to link everything up nicely anyway.

 $f = new UploadField('FrontImages', 'Front Images (Maximum of 10 images. Allowed files: .jpg, .jpeg, .png or .gif)', $this->FrontImages()); 

I hope this helps someone in the future :)