Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UtilController extends Controller {
- function updateshowPosterImage() {
- $Page = Page::get()->filter("ID","17633")->First();
- if(!$Page->BannerImageID) {
- $page_name = $Page->MenuTitle;
- $file_name = 'banner-image-'.$show_name.'.jpg';
- $file_path = $themeFolder.'/images/page/banner/'.$file_name;
- $file_upload_path = sprintf("%s/page/banner",Config::inst()->get('Upload', 'uploads_folder'));
- if (!file_exists(ASSETS_PATH . DIRECTORY_SEPARATOR . $file_upload_path)) {
- mkdir(ASSETS_PATH . DIRECTORY_SEPARATOR . $file_upload_path, 0777, true);
- }
- $file_upload_file = $file_upload_path . DIRECTORY_SEPARATOR .$file_name;
- $file_contents = '';
- set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
- // error was suppressed with the @-operator
- if (0 === error_reporting()) {
- return false;
- }
- throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
- });
- try {
- if (Director::fileExists($file_path)) {
- $uploadImage = function() use ($file_name, $file_upload_file,$file_path ) {
- if(!file_exists(ASSETS_PATH . DIRECTORY_SEPARATOR. $file_upload_file)) {
- copy(BASE_PATH . DIRECTORY_SEPARATOR . $file_path, ASSETS_PATH . DIRECTORY_SEPARATOR. $file_upload_file);
- }
- // emulates the $_FILES array
- $fileconfig = array(
- 'name' => $file_name,
- 'type' => 'text/plaintext',
- 'size' => filesize(ASSETS_PATH . DIRECTORY_SEPARATOR . $file_upload_file),
- 'tmp_name' => ASSETS_PATH . DIRECTORY_SEPARATOR . $file_upload_file,
- 'extension' => 'jpg',
- 'error' => UPLOAD_ERR_OK,
- );
- //test upload into default folder
- $upload = new Upload();
- $upload->validate($fileconfig);
- $upload->validator->setAllowedExtensions(array('jpg'));
- $upload->load($fileconfig);
- Debug::show($upload->getErrors());
- return $upload->getFile();
- };
- $image = $uploadImage();
- Debug::show($image);
- }
- } catch(Exception $e) {
- Debug::show($e->getMessage());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement