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

multiple image upload saves only the last one


Go to End


4 Posts   1117 Views

Avatar
santosmateo

Community Member, 14 Posts

14 October 2015 at 1:23pm

Edited: 14/10/2015 1:25pm

Hello, I 'm following the tutorials from SilverStripe website, and I added a page on the CMS to upload images .

I have two problems :
the first is when I upload the picture, and try to return to the previus page, the CMS goes blank and I have to refresh to see the content again .

The other is that when I add multiple pictures with

$ uploader- > setAllowedMaxFileNumber ( 20);

only the last I've added is saved.

I hope you can help me, I 'm starting .

Thank you!

Proyecto.php

class Proyecto extends Page {
..
	private static $has_many = array(
		'Galeria' => 'GaleriaProyecto'
	);

	public function getCMSFields(){
		$fields = parent::getCMSFields();
		
$fields->addFieldToTab('Root.Galeria', GridField::create(
			'Galeria',
			'Imagenes del proyecto',
			$this->Galeria(),
			GridFieldConfig_RecordEditor::create()
		)); 

		return $fields;
}
}
class Proyecto_Controller extends Page_Controller  {}

GaleriaProyecto.php

 class GaleriaProyecto extends dataObject {


 	private static $has_one = array(
	 'Imagen' => 'Image',
  		'Proyecto' => 'Proyecto'
 	);



 	private static $summary_fields = array(
 		'Imagen.CMSThumbnail' => ''
 	);

	public function getCMSFields() {
 		$fields = FieldList::create(
 			$uploader = UploadField::create('Imagen')
 		);

 		$uploader -> setFolderName('Galeria');
		$uploader->setAllowedMaxFileNumber(20);
 		$uploader -> getValidator()->setAllowedExtensions(array('png','jpg','jpeg','gif'));
 		return $fields;
 	} 
 }

Avatar
helenclarko

Community Member, 166 Posts

14 October 2015 at 4:48pm

Edited: 14/10/2015 4:52pm

Hi Santosmateo,

Seems like an odd way to do it, but to use the "setAllowedMaxFileNumber(20);" you will need to use a has_Many array.
This will allow you to upload more than one file.

Give the following a shot:

 class GaleriaProyecto extends dataObject {

 	private static $has_one = array(
  		'Proyecto' => 'Proyecto'
 	);

	private static $has_many = array(
		'Imagen' => 'Image',
 	);

 	private static $summary_fields = array(
 		'Imagen.CMSThumbnail' => ''
 	);

	public function getCMSFields() {
 		$fields = FieldList::create(
 			$uploader = UploadField::create('Imagen')
 		);

 		$uploader -> setFolderName('Galeria');
		$uploader->setAllowedMaxFileNumber(20);
 		$uploader ->allowedExtensions = array('png', 'jpg', 'jpeg', 'gif');
 		return $fields;
 	} 
 }

-helenclarko

Avatar
santosmateo

Community Member, 14 Posts

15 October 2015 at 2:55am

thank you very much for responding, helenclarko.
With the change that you suggest, and after adding images, when pressing "create" to return to the previous page, the page is blank, or when I try to access the page again.

I have something in code that is not working well.

Thanks again, I'll keep trying.

Avatar
helenclarko

Community Member, 166 Posts

15 October 2015 at 8:40am

Hi Santosmateo,

Usually a blank page requiring a refresh is caused by a closed php file or a blank php file.
Check your "mysite/code" folder for any .php files which have ending php tags or are empty.

I could be wrong, but I believe this is the likely cause of the problem.

You could also add the ?isDev=1 to the end of your URL before hitting sae and see if it throws you an error.

-helenclarko