PHP code example of firebrandhq / s3fileupload

1. Go to this page and download the library: Download firebrandhq/s3fileupload library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

firebrandhq / s3fileupload example snippets



class Page extends SiteTree {

	private static $has_one = array(
        'File' => 'S3File'
	);

    public function getCMSFields() {
		$fields = parent::getCMSFields();

		$s3Field = S3FileUploadField::create('File', 'S3 File')
            ->setAllowedMaxFileNumber(1);

        // You can omit the following 2 lines.
        // It will fallback on the YML configuration.
        $s3Field->setBucket('YourBucketName');
        $s3Field->setRegion('us-east-1');

		$fields->insertBefore(
			S3FileUploadField::create('S3File', 'S3 File')
				->setAllowedMaxFileNumber(1),
			'Description'
		);

		$fields->addFieldToTab('Root.Main',$s3Field);

		return $fields;
	}

}