Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class UtilController extends Controller {
  2.     function updateshowPosterImage() {
  3.                 $Page = Page::get()->filter("ID","17633")->First();
  4.         if(!$showPage->PosterImageID) {
  5.             $page_name = $Page->MenuTitle;
  6.             $file_name = 'poster-image.jpg';
  7.             $file_path = $themeFolder.'/images/page/banner/'.$file_name;
  8.             $file_upload_path = sprintf("%s/spage/banner",Config::inst()->get('Upload', 'uploads_folder'));
  9.             if (!file_exists(ASSETS_PATH . DIRECTORY_SEPARATOR . $file_upload_path)) { 
  10.                     mkdir(ASSETS_PATH . DIRECTORY_SEPARATOR . $file_upload_path, 0777, true);
  11.             }
  12.             $folder = Folder::find_or_make($file_upload_path);
  13.             $file_upload_file =  $file_upload_path . DIRECTORY_SEPARATOR .$file_name;
  14.             set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
  15.                 // error was suppressed with the @-operator
  16.                 if (0 === error_reporting()) {
  17.                 return false;
  18.                 }
  19.  
  20.                 throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
  21.             });
  22.            
  23.             try {
  24.                 if (Director::fileExists($file_path)) {
  25.                     $uploadImage = function() use ($file_name, $file_upload_file,$file_path ,$folder) {
  26.                         if(!file_exists(ASSETS_PATH . DIRECTORY_SEPARATOR. $file_upload_file)) {
  27.                             copy(BASE_PATH . DIRECTORY_SEPARATOR . $file_path, ASSETS_PATH . DIRECTORY_SEPARATOR. $file_upload_file);
  28.                         }
  29.                         $file = new File();
  30.                         $file->Name = $file_name;
  31.                         $file->setName($file_name);
  32.                         $file->ClassName = $file->get_class_for_file_extension('jpg');
  33.                         $file->FileName = ASSETS_DIR . DIRECTORY_SEPARATOR . $file_upload_file;
  34.                         $file->ParentID = $folder->ID;
  35.                         $file->OwnerID =  Member::currentUserID();
  36.                         $file->write();
  37.                         return $file;
  38.                     };
  39.                     $image = $uploadImage();
  40.    
  41.                 }
  42.             } catch(Exception $e) {
  43.                 Debug::show($e->getMessage());
  44.             }
  45.         }
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement