21310 Posts in 5739 Topics by 2604 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 226 Views |
-
UploadField for Image and File

13 December 2012 at 9:49pm
Hi, I'm new to SilverStripe and I want to upload Files such as doc, docx, pdf, txt as well as jpg, png...
what is a good way to do this?I currently have this,
<?php
class ResourcesPage extends Page {
static $db = array(
);
static $has_one = array(
'UploadedFile' => 'File',
'UploadedImage' => 'Image'
);
public function populateDefaults(){
parent::populateDefaults();
}
public function getCMSFields() {
$fields = parent::getCMSFields();
$fileUpload = new UploadField( 'UploadedFile', 'Select PDF file' );
$imageUpload = new UploadField( 'UploadedImage', 'Select image' );
$fields->addFieldToTab( 'Root.Files', $fileUpload );
$fields->addFieldToTab( 'Root.Files', $imageUpload );return $fields;
}
}
class ResourcesPage_Controller extends Page_Controller {
}
Is it possible to have one UploadField that can upload a File/Image?in my template
<a href="$UploadedFile.Link" >Download Link</a>
<a href="$UploadedImage.Link" >Download Link</a>
In the front end, a link will be provided so the user can download the File/Imagenot sure about the
static $has_one = array(
'UploadedFile' => 'File',
'UploadedImage' => 'Image'
);any suggesstions?
-
Re: UploadField for Image and File

15 December 2012 at 11:20am
The new UploadField does support multiple files.
You currently have it setup using a $has_one relationship which will only allow it one file. Change it to a $many_many and you will be able to upload as many files as you want, both images and files. No need to setup 2 different relationships for image and file. Then just loop through your template to access the files.
-
Re: UploadField for Image and File

4 January 2013 at 4:29am
Thanks,
yeah my teammate told me the same thing
got an error before,
guess it wasn't because of that.
my bad
| 226 Views | ||
|
Page:
1
|
Go to Top |


