예제 #1
0
파일: downloads.php 프로젝트: unisexx/imac
 function approve($id)
 {
     if ($_POST) {
         $rs = new Download($id);
         $rs->from_array($_POST);
         $rs->save();
     }
 }
예제 #2
0
파일: Files.php 프로젝트: hkhateb/linet3
 public function save($runValidation = true, $attributes = NULL)
 {
     $a = parent::save($runValidation, $attributes);
     if ($this->public && $this->hash == '') {
         $download = new Download();
         $download->file_id = $this->id;
         $download->company_id = Yii::app()->user->Company;
         $this->hash = $download->id = md5(mt_rand());
         $download->save();
     }
     return $a;
 }
 /**
  * Save new downloadable file to path and record in DB
  *
  * @return mixed
  */
 public function uploadFile()
 {
     if (Input::hasFile('upload')) {
         $filename = Input::file('upload')->getClientOriginalName();
         Input::file('upload')->move(public_path('files'), $filename);
     }
     $displayName = Input::get('display_name');
     $description = Input::get('description');
     $newFile = new Download();
     $newFile->display_name = $displayName;
     $newFile->filename = $filename;
     $newFile->description = $description;
     $newFile->save();
     return Redirect::back()->with('flash_message', 'File Uploaded');
 }
	public function create() {
	
		//	make sure user has rights to create
		self::__checkPermission('downloads_new');
		
		//	get the validated input
		$input = $this->__validate($_POST);
		
		//	attempt to upload the image
		if (!$upload = $this->__upload('download',$input['name'])) {
			redirect(get_url('plugin/downloads/add'));
		}
		$input = array_merge($input,$upload);
		
		//	set the created date
		$input['created'] = date('Y-m-d H:i:s');
		$input['updated'] = date('Y-m-d H:i:s');
		
		//	save the new record
		$download = new Download($input);
		if (!$download->save()) {
			
			//	determine the destination directory
			$dstdir = CMS_ROOT."/{$this->settings['download_path']}/";
			
			//	remove the uploaded file since save failed
			if (!unlink($dstdir.$download->filename)) {
				$this->__log(__('error encountered creating new download'),self::LOG_ERROR);
				Flash::set('error',__('Could not save record in database and permission denied removing uploaded file!'));
				redirect(get_url('plugin/downloads/add'));
			}
			
			$this->__log(__('error encountered creating new download'),self::LOG_ERROR);
			Flash::set('error',__('Could not save record in database!'));
			redirect(get_url('plugin/downloads/add'));
		}
		
		//	add the tags
		$this->__storetags($_POST['tags'],$download->id);
		
		//	pat on the back and send back to the list
		$this->__log(__('created new download').' "'.$download->name.'"');
		Flash::set('success',__('Record saved!'));
		redirect(get_url('plugin/downloads/edit/'.$download->id));

	}//*/