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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

SWFUploadFileIFrameField and SS 2.4

Go to End

9 Posts   2483 Views


Community Member, 81 Posts

9 July 2010 at 1:24am

It's not really IFrame, but yesterday i decided that it's too hard to add images to the Staff section one by one and i don't like ImageGallery module 'cos it generates thumbs in different way and it's too heavy for example u don't need so more different lightboxes and something else i don't remember, but anyway StaffPage, ContactPage, GalleryImage and etc implents one interface in my code.

Well, ok:


function getCMSFields() {
		$fields = parent::getCMSFields();
		SWFUploadConfig::addPostParam('ID', $this->ID);
		SWFUploadConfig::addPostParam('Locale', $this->Locale);
			new SWFUploadField(
					'file_upload_limit' => 10, // how many files can be uploaded
					'file_queue_limit' => 10, // how many files can be in the queue at once
					'browse_button_text' => 'Upload Images ...',
					'upload_url' => Director::absoluteURL('StaffHolder_Controller/handleswfupload'),
					'required' => 'true',
					//'debug' => 'true'
		return $fields;


public function handleswfupload() {
		$parent = DataObject::get_by_id('StaffHolder', $_POST['ID']); // Get parent for permission check
		if( $parent->canCreate(Member::currentUser()) ) { // User Permission Check
		if(isset($_FILES['swfupload_file']) && !empty($_FILES['swfupload_file'])) {
			set_time_limit(1200); // 20 mins
			// Assuming its a decendant of File
			$image = new Image();
			if(class_exists("Upload")) {
				$u = new Upload();
				$u->loadIntoFile($_FILES['swfupload_file'], $image);
			else {
			$image->write(); // Save image
			// Page Creating
			$title = substr($_POST['Filename'], 0, strlen($_POST['Filename'])-4); // Get title from file name
			$new = new StaffPage(); // Create new staff page		
			$new->populateDefaults(); // if defaults are set
			$new->setParent($_POST['ID']); // set parent page
			$new -> update(
					'MenuTitle' => $title,
					'Title' => $title,
					'Locale' => $_POST['Locale'],
					'PhotoID' => $image->ID // adding image
			$new->writeToStage('Stage'); // Save Page
			die('Image Loaded');
		} else die('Image isn\' sended');
		} else die ('Permission Error');

Go to Top