Ejemplo n.º 1
0
 public function action_commit()
 {
     $item = new Model_Item();
     $item->name = $_POST['item_name'];
     $item->phonetic = $_POST['phonetic'];
     $item->category = $_POST['category'];
     if ($_POST['category'] == 'ピザ') {
         $item->unit_price_s = $_POST['s_money'];
         $item->unit_price_m = $_POST['m_money'];
         $item->unit_price_l = $_POST['l_money'];
     } else {
         $item->unit_price = $_POST['money'];
     }
     $item->explanatory = $_POST['explanation'];
     $item_img = new Model_Itemimg();
     // 初期設定
     $config = array('path' => DOCROOT . DS . 'assets/img', 'randomize' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'));
     // アップロード基本プロセス実行
     Upload::process($config);
     // 検証
     if (Upload::is_valid()) {
         // 設定を元に保存
         Upload::save();
         $uploadfile = Upload::get_files(0);
         // 情報をデータベースに保存する場合
         $item_img->path = $uploadfile["name"];
     }
     foreach (Upload::get_errors() as $file) {
         // $file['errors']の中にエラーが入っているのでそれを処理
     }
     $item_img->save();
     $item->img_id = $item_img->id;
     $item->save();
     return View::forge('top/top');
 }
Ejemplo n.º 2
0
 public function addPortfolio($no)
 {
     $tempFileName = 'file' . rand(10000000, 99999999);
     $validationFiles = Validation::factory($_FILES)->rules('portfolioSmall', array(array('Upload::not_empty'), array('Upload::image')))->rules('portfolioBig', array(array('Upload::not_empty'), array('Upload::image')));
     $validationText = Validation::factory($_POST)->rule('name', 'not_empty');
     if ($validationFiles->check() and $validationText->check()) {
         Upload::save($validationFiles['portfolioSmall'], $tempFileName . '.png', Upload::$default_directory);
         Upload::save($validationFiles['portfolioBig'], $tempFileName . '.jpg', Upload::$default_directory);
         $tempFileNamePath = Upload::$default_directory . $tempFileName;
         $filePath = Kohana::$config->load('portfolio')->get('filePath');
         if (copy($tempFileNamePath . '.png', $filePath . $tempFileName . '.png') and copy($tempFileNamePath . '.jpg', $filePath . $tempFileName . '.jpg')) {
             unlink($tempFileNamePath . '.png');
             unlink($tempFileNamePath . '.jpg');
             $this->path = $tempFileName;
             $this->name = HTML::chars($_POST['name']);
             $this->type = HTML::chars($_POST['type']);
             if (!$no) {
                 $this->no = (int) $this->maxNoPortfolio() + 1;
             } else {
                 $this->no = $no;
             }
             $this->create();
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
 public function _upload_image(Validate $array, $input)
 {
     if ($array->errors()) {
         // Don't bother uploading
         return;
     }
     // Get the image from the array
     $image = $array[$input];
     if (!Upload::valid($image) or !Upload::not_empty($image)) {
         // No need to do anything right now
         return;
     }
     if (Upload::valid($image) and Upload::type($image, $this->types)) {
         $filename = strtolower(Text::random('alnum', 20)) . '.jpg';
         if ($file = Upload::save($image, NULL, $this->directory)) {
             Image::factory($file)->resize($this->width, $this->height, $this->resize)->save($this->directory . $filename);
             // Update the image filename
             $array[$input] = $filename;
             // Delete the temporary file
             unlink($file);
         } else {
             $array->error('image', 'failed');
         }
     } else {
         $array->error('image', 'valid');
     }
 }
Ejemplo n.º 4
0
 /**
  * 上传
  */
 public function actionBasicExecute()
 {
     if (XUtils::method() == 'POST') {
         $adminiUserId = self::_sessionGet('adminiUserId');
         $file = XUpload::upload($_FILES['imgFile']);
         if (is_array($file)) {
             $model = new Upload();
             $model->user_id = intval($accountUserId);
             $model->file_name = $file['pathname'];
             $model->thumb_name = $file['paththumbname'];
             $model->real_name = $file['name'];
             $model->file_ext = $file['extension'];
             $model->file_mime = $file['type'];
             $model->file_size = $file['size'];
             $model->save_path = $file['savepath'];
             $model->hash = $file['hash'];
             $model->save_name = $file['savename'];
             $model->create_time = time();
             if ($model->save()) {
                 exit(CJSON::encode(array('state' => 'success', 'fileId' => $model->id, 'realFile' => $model->real_name, 'message' => '上传成功', 'file' => $file['pathname'])));
             } else {
                 @unlink($file['pathname']);
                 exit(CJSON::encode(array('state' => 'error', 'message' => '数据写入失败,上传错误')));
             }
         } else {
             exit(CJSON::encode(array('error' => 1, 'message' => '上传错误')));
         }
     }
 }
 /**
  * Attempts to upload a file, adds it to the database and removes other database entries for that file type if they are asked to be removed
  * @param  string  $field             The name of the $_FILES field you want to upload
  * @param  boolean $upload_type       The type of upload ('news', 'gallery', 'section') etc
  * @param  boolean $type_id           The ID of the item (above) that the upload is linked to
  * @param  boolean $remove_existing   Setting this to true will remove all existing uploads of the passed in type (useful for replacing news article images when a new one is uploaded for example)
  * @return object                     Returns the upload object so we can work with the uploaded file and details
  */
 public static function upload($field = 'image', $upload_type = false, $type_id = false, $remove_existing = false)
 {
     if (!$field || !$upload_type || !$type_id) {
         return false;
     }
     $input = Input::file($field);
     if ($input && $input['error'] == UPLOAD_ERR_OK) {
         if ($remove_existing) {
             static::remove($upload_type, $type_id);
         }
         $ext = File::extension($input['name']);
         $filename = Str::slug(Input::get('title'), '-');
         Input::upload('image', './uploads/' . $filename . '.' . $ext);
         $upload = new Upload();
         $upload->link_type = $upload_type;
         $upload->link_id = $type_id;
         $upload->filename = $filename . '.' . $ext;
         if (Koki::is_image('./uploads/' . $filename . '.' . $ext)) {
             $upload->small_filename = $filename . '_small' . '.' . $ext;
             $upload->thumb_filename = $filename . '_thumb' . '.' . $ext;
             $upload->image = 1;
         }
         $upload->extension = $ext;
         $upload->user_id = Auth::user()->id;
         $upload->save();
         return $upload;
     }
 }
 /**
  * Upload the file and store
  * the file path in the DB.
  */
 public function store()
 {
     // Rules
     $rules = array('name' => 'required', 'file' => 'required|max:20000');
     $messages = array('max' => 'Please make sure the file size is not larger then 20MB');
     // Create validation
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $directory = "uploads/files/";
     // Before anything let's make sure a file was uploaded
     if (Input::hasFile('file') && Request::file('file')->isValid()) {
         $current_file = Input::file('file');
         $filename = Auth::id() . '_' . $current_file->getClientOriginalName();
         $current_file->move($directory, $filename);
         $file = new Upload();
         $file->user_id = Auth::id();
         $file->project_id = Input::get('project_id');
         $file->name = Input::get('name');
         $file->path = $directory . $filename;
         $file->save();
         return Redirect::back();
     }
     $upload = new Upload();
     $upload->user_id = Auth::id();
     $upload->project_id = Input::get('project_id');
     $upload->name = Input::get('name');
     $upload->path = $directory . $filename;
     $upload->save();
     return Redirect::back();
 }
Ejemplo n.º 7
0
 /**
  * Uploads a file if we have a valid upload
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @param   bool   $loaded
  * @return  string|NULL
  */
 public function save($model, $value, $loaded)
 {
     $original = $model->get($this->name, FALSE);
     // Upload a file?
     if (is_array($value) and Upload::valid($value)) {
         if (FALSE !== ($filename = Upload::save($value, NULL, $this->path))) {
             // Chop off the original path
             $value = str_replace(realpath($this->path) . DIRECTORY_SEPARATOR, '', $filename);
             // Ensure we have no leading slash
             if (is_string($value)) {
                 $value = trim($value, '/');
             }
             // Delete the old file if we need to
             if ($this->delete_old_file and $original != $this->default) {
                 $path = realpath($this->path) . $original;
                 if (file_exists($path)) {
                     unlink($path);
                 }
             }
         } else {
             $value = $this->default;
         }
     }
     return $value;
 }
 /**
  * アップロードファイルを指定のフォルダに移動する
  *
  * @access public
  * @param array $config アップロードの設定
  * @return void
  * @author kobayashi
  * @author ida
  */
 public static function moveUploadedFile($config)
 {
     $default = array('ext_whitelist' => array('jpg'), 'randomize' => true);
     $config = array_merge($default, $config);
     \Upload::process($config);
     $is_upload = false;
     $result = array();
     if (\Upload::is_valid()) {
         \Upload::save();
         $files = \Upload::get_files();
         foreach ($files as $file) {
             $result[$file['field']] = $file;
         }
         $is_upload = true;
     } else {
         $error_files = \Upload::get_errors();
         foreach ($error_files as $file) {
             foreach ($file['errors'] as $error) {
                 if ($error['error'] != \Upload::UPLOAD_ERR_NO_FILE) {
                     $result[$file['field']] = $file;
                     $is_upload = false;
                 }
             }
         }
         if (empty($result)) {
             $is_upload = true;
         }
     }
     return array($is_upload, $result);
 }
Ejemplo n.º 9
0
 public function action_upload()
 {
     $data = array();
     $data['errors'] = array();
     if ($this->isPressed('btnSubmit')) {
         $user = ORM::factory('user');
         $file = Validation::factory($_FILES);
         $file->rule('codesFile', 'Upload::not_empty');
         $file->rule('codesFile', 'Upload::valid');
         $file->rule('codesFile', 'Upload::type', array(':value', array('csv')));
         $file->rule('codesFile', 'Upload::size', array(':value', '1M'));
         if ($file->check()) {
             $savedfilename = Upload::save($file['codesFile'], 'tmpCodesList.csv', 'files');
             if ($savedfilename === FALSE) {
                 throw new Exception('Unable to save tmpCodesList.csv file!');
             }
             $data['errors'] = $user->importUsers($savedfilename);
             unlink($savedfilename);
             if (count($data['errors']) == 0) {
                 $data['success'] = TRUE;
             }
         } else {
             $data['errors'] = $file->errors('upload', FALSE);
         }
     }
     $this->tpl->content = View::factory('admin/uploadusers', $data);
 }
Ejemplo n.º 10
0
 /**
  * Register
  *
  * @access public
  * @author Dao Anh Minh
  */
 public function action_register()
 {
     $view = View::forge('admin/gallery/register');
     $view->err = array();
     $view->data = array('description' => '');
     if (Input::method() == 'POST') {
         Upload::process($this->config);
         if (Upload::is_valid()) {
             Upload::save();
             $file_name = Upload::get_files(0)['saved_as'];
             if (!empty($file_name)) {
                 $img = Model_Img::forge();
                 $img->name = $file_name;
                 $img->active = Input::post('active', false);
                 $img->type = IMG_GALLERY;
                 $img->info = serialize(array('info' => Input::post('description', '')));
                 $img->save();
                 Session::set_flash('success', 'Đăng ký hình thành công');
                 Response::redirect('admin/gallery');
             } else {
                 Session::set_flash('error', 'Chỉ chấp nhận file hình');
                 Response::redirect('admin/gallery/register');
             }
         } else {
             Session::set_flash('error', 'Hình bạn chọn không phù hợp, vui lòng thử lại');
             $view->data = Input::post();
         }
     }
     $this->template->title = 'Đăng ký hình';
     $this->template->content = $view;
 }
Ejemplo n.º 11
0
 /**
  * Store a newly created upload in storage.
  *
  * @return Response
  */
 public function store()
 {
     Upload::setRules('store');
     if (!Upload::canCreate()) {
         return $this->_access_denied();
     }
     $file = Input::file('file');
     $hash = md5(microtime() . time());
     $data = [];
     $data['path'] = public_path() . '/uploads/' . $hash . '/';
     mkdir($data['path']);
     $data['url'] = url('uploads/' . $hash);
     $data['name'] = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $file->getClientOriginalName());
     $data['type'] = $file->getMimeType();
     $data['size'] = $file->getSize();
     $data['uploadable_type'] = Request::header('X-Uploader-Class');
     $data['uploadable_id'] = Request::header('X-Uploader-Id') ? Request::header('X-Uploader-Id') : 0;
     $data['token'] = Request::header('X-CSRF-Token');
     $file->move($data['path'], $data['name']);
     if (property_exists($data['uploadable_type'], 'generate_image_thumbnails')) {
         Queue::push('ThumbnailService', array('path' => $data['path'] . '/' . $data['name']));
     }
     $upload = new Upload();
     $upload->fill($data);
     if (!$upload->save()) {
         return $this->_validation_error($upload);
     }
     if (Request::ajax()) {
         return Response::json($upload, 201);
     }
     return Redirect::back()->with('notification:success', $this->created_message);
 }
Ejemplo n.º 12
0
 public function action_save()
 {
     if ($_POST && $_FILES) {
         $imageChanged = false;
         $data = (object) $this->sanitize($_POST);
         $update = false;
         if ($data->id == "") {
             $editorial = ORM::factory("editorial");
         } else {
             $editorial = ORM::factory("editorial", $data->id);
         }
         if (in_array($_FILES['image']['type'], $this->allowed)) {
             Upload::$default_directory = Kohana::config('myshot.basePath');
             if ($stage_path = Upload::save($_FILES['image'])) {
                 $imageChanged = true;
                 Library_Akamai::factory()->addToDir($stage_path, 'editorials');
             }
         }
         $editorial->title = $data->title;
         $editorial->image = $imageChanged ? Kohana::config('myshot.cdn') . 'editorials/' . basename($stage_path) : $editorial->image;
         $editorial->image_alt = $data->image_alt;
         $editorial->link = $data->link;
         $editorial->link_text = $data->link_text;
         $editorial->text = $data->text;
         $editorial->save();
         Message::set(Message::SUCCESS, $update ? "You have sucessfully updated the editorial." : "You have sucessfully added the editorial.");
     }
     Request::instance()->redirect('admin/editorials');
 }
Ejemplo n.º 13
0
 public function uploadfile()
 {
     if ($_GET['from'] == 'swfupload') {
         $uid = intval($_GET['uid']);
         $username = trim($_GET['username']);
         $token = sha1($uid . $username . formhash());
         if (!$uid || !$username || $token != $_GET['token']) {
             echo json_encode(array('state' => 0, 'info' => 'nologin'));
             exit;
         }
     } else {
         $this->_checkuser();
         $uid = $this->uid;
     }
     $config = $GLOBALS['G']['config']['output'];
     $upload = new Upload();
     $attachment = 'attach/' . date('Y') . '/' . date('m') . '/' . $upload->setfilename();
     if ($upload->save(ROOT_PATH . '/' . $config['attachdir'] . '/' . $attachment)) {
         $attachdata = array('uid' => $uid, 'attachname' => $upload->oriname(), 'attachment' => $attachment, 'attachsize' => $upload->size(), 'attachtype' => $upload->type(), 'attachtime' => time());
         $attachdata['attachid'] = $this->t('attachment')->insert($attachdata, true);
         echo json_encode(array('state' => 1, 'data' => $attachdata));
         exit;
     } else {
         echo json_encode(array('state' => 0, 'info' => 'Upload Failed(' . $upload->error . ')'));
         exit;
     }
 }
Ejemplo n.º 14
0
 /**
  * 编辑器文件上传
  */
 public function actionUpload()
 {
     if (XUtils::method() == 'POST') {
         $file = XUpload::upload($_FILES['imgFile']);
         if (is_array($file)) {
             $model = new Upload();
             $model->user_id = intval($admini['userId']);
             $model->file_name = CHtml::encode($file['pathname']);
             $model->thumb_name = CHtml::encode($file['paththumbname']);
             $model->real_name = CHtml::encode($file['name']);
             $model->file_ext = $file['extension'];
             $model->file_mime = $file['type'];
             $model->file_size = $file['size'];
             $model->save_path = $file['savepath'];
             $model->hash = $file['hash'];
             $model->save_name = $file['savename'];
             $model->create_time = time();
             if ($model->save()) {
                 exit(CJSON::encode(array('error' => 0, 'url' => Yii::app()->baseUrl . '/' . $file['pathname'])));
             } else {
                 @unlink($file['pathname']);
                 @unlink($file['paththumbname']);
                 exit(CJSON::encode(array('error' => 1, 'message' => '上传错误')));
             }
         } else {
             exit(CJSON::encode(array('error' => 1, 'message' => '上传错误:' . $file)));
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * 首页
  *
  */
 public function action_index()
 {
     if (!empty($_FILES)) {
         $savePath = DOCROOT . 'src_csv/' . $this->auth['uid'] . '/';
         // 保存目录
         $upload = new Upload(array('size' => 10240, 'ext' => array('csv')));
         $upload->set_path($savePath);
         try {
             $result = $upload->save($_FILES['upload_file']);
             $date = array($this->auth['uid'], $this->auth['username'], $result['name'], $result['saveName'], $result['size'], date('Y-m-d H:i:s'));
             $row = DB::insert('imgup_movestore', array('uid', 'uname', 'csv_file', 'src_file', 'freesize', 'upload_time'))->values($date)->execute();
             $content = $this->changeCharacter($savePath . $result['saveName']);
             //preg_match_all("/(src)=[\"|'| ]{0,}((https?\:\/\/.*?)([^>]*[^\.htm]\.(gif|jpg|bmp|png)))/i",$content, $match);
             //preg_match_all("/[\"|'| ]{0,}((https?\:\/\/[a-zA-Z0-9_\.\/]*?)([^<\>]*[^\.htm]\.(gif|jpg|bmp|png)))/i", $content, $match);
             preg_match_all("/\\<img.*?src\\=[\"\\']+[ \t\n]*(https?\\:\\/\\/.*?)[ \t\n]*[\"\\']+[^>]*>/i", $content, $match);
             $imgArr = array_unique($match[1]);
             foreach ($imgArr as $value) {
                 # 去除本站的图片地址
                 if (!preg_match("/^http:\\/\\/[\\w\\.\\-\\_]*wal8\\.com/i", $value)) {
                     DB::insert('store_imgs', array('sid', 'url', 'add_time', 'uid'))->values(array($row[0], $value, time(), $this->auth['uid']))->execute();
                 }
             }
             $link[] = array('text' => '返回', 'href' => '/shopmove');
             $this->show_message('上传' . $result['name'] . '文件成功', 1, $link);
         } catch (Exception $e) {
             $link[] = array('text' => '返回', 'href' => '/shopmove');
             $this->show_message($e->getMessage(), 0, $link);
         }
     }
 }
Ejemplo n.º 16
0
 public function saveArchivo($files)
 {
     $dir = DOCROOT . 'files';
     $ext = pathinfo($files['name'], PATHINFO_EXTENSION);
     $slug = strtolower(Text::random('alnum', 10)) . '.' . $ext;
     $file = Upload::save($files, $slug, $dir);
     return $slug;
 }
Ejemplo n.º 17
0
 function upload()
 {
     $upload = new Upload();
     $data = $upload->save('products');
     //$data = fn_upload('banner');
     $this->assign('message', $data);
     $this->setReturnType('message');
 }
Ejemplo n.º 18
0
 public function action_upload()
 {
     $submitted = FALSE;
     if ($this->request->method() === 'POST' && $this->request->post()) {
         if (Arr::get($this->request->post(), 'save') !== null) {
             $submitted = TRUE;
             $document = ORM::factory('document');
             $validator = $document->validator(array_merge($this->request->post(), $_FILES));
             $validator->bind(':files', $_FILES['name']);
             if ($validator->check()) {
                 $filename = Upload::save($_FILES['name'], NULL, UPLOAD_PATH);
                 $document = ORM::factory('document');
                 $document->values($this->request->post());
                 $document->name = basename($filename);
                 $document->time = time();
                 $document->save();
                 $document->add('courses', $this->request->post('course_id'));
                 $document->add('roles', $this->request->post('role'));
                 foreach ($this->request->post('course_id') as $course_id) {
                     $feed = new Feed_Document();
                     $feed->set_action('add');
                     $feed->set_course_id($course_id);
                     $feed->set_respective_id($document->id);
                     $feed->set_actor_id(Auth::instance()->get_user()->id);
                     $stream_data = array('course_id' => $course_id, 'role_id' => $this->request->post('role'));
                     $feed->streams($stream_data);
                     $feed->save();
                 }
                 Request::current()->redirect('document');
             } else {
                 $this->_errors = $validator->errors('document');
             }
         }
     }
     $courses = Model_Course::courses()->as_array('id', 'name');
     $course_id = Session::instance()->get('course_id');
     //remove the current course from the list
     unset($courses[$course_id]);
     $form = new Stickyform('document/upload', array('enctype' => "multipart/form-data"), $submitted ? $this->_errors : array());
     $form->default_data = array('title' => '', 'user_id' => Auth::instance()->get_user()->id, 'course_id' => 0, 'role' => 0);
     $form->posted_data = $submitted ? $this->request->post() : array();
     $form->append('Title', 'title', 'text');
     $form->append('Access To', 'role', 'text');
     $form->append('User', 'user_id', 'hidden');
     $form->append('File', 'name', 'file');
     $form->append('Also add to', 'course_id', 'select', array('options' => $courses, 'attributes' => array('multiple' => 'multiple', 'name' => 'course_id[]')));
     $form->append('Upload', 'save', 'submit', array('attributes' => array('class' => 'button')));
     $form->process();
     $course = ORM::factory('course', $course_id);
     $roles = ORM::factory('role')->find_all()->as_array('id', 'name');
     $view = View::factory('document/form')->bind('form', $form)->bind('course', $course)->bind('roles', $roles);
     Breadcrumbs::add(array('Courses', Url::site('course')));
     Breadcrumbs::add(array('Documents', Url::site('document')));
     Breadcrumbs::add(array('Upload', Url::site('document/upload')));
     $this->content = $view;
 }
Ejemplo n.º 19
0
 public function action_index()
 {
     $is_chenged = false;
     if ($this->user->bank == null) {
         $this->user->bank = Model_Bank::forge();
         $this->user->bank->user_id = $this->user->id;
         $this->user->bank->save();
     }
     if (Input::post("firstname", null) != null and Security::check_token()) {
         $email = Input::post("email", null);
         if ($email != $this->user->email) {
             $check_user = Model_User::find("first", ["where" => [["email" => $email]]]);
             if ($check_user == null) {
                 $this->email = $email;
             } else {
                 $data["error"] = "This email is already in use.";
             }
         }
         $config = ["path" => DOCROOT . "assets/img/pictures/", 'randomize' => true, 'auto_rename' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')];
         Upload::process($config);
         if (Upload::is_valid()) {
             Upload::save();
             $saved_result = Upload::get_files();
             $file_name = $saved_result[0]['saved_as'];
             $image = Image::load($config["path"] . $file_name);
             $image->crop_resize(200, 200)->save($config["path"] . "m_" . $file_name);
             $image->crop_resize(86, 86)->save($config["path"] . "s_" . $file_name);
             $this->user->img_path = $file_name;
         } else {
             $error = Upload::get_errors();
         }
         if (!isset($data["error"])) {
             $this->user->firstname = Input::post("firstname", "");
             $this->user->middlename = Input::post("middlename", "");
             $this->user->lastname = Input::post("lastname", "");
             $this->user->google_account = Input::post("google_account", "");
             $this->user->pr = Input::post("pr", "");
             $this->user->educational_background = Input::post("educational_background", "");
             $this->user->enchantJS = Input::post("enchantJS", 0);
             $this->user->trial = Input::post("trial", 0);
             $this->user->save();
             $this->user->bank->name = Input::post("bank_name", "");
             $this->user->bank->branch = Input::post("bank_branch", "");
             $this->user->bank->account = Input::post("bank_account", "");
             $this->user->bank->number = Input::post("bank_number", "");
             $this->user->bank->etc = Input::post("bank_etc", "");
             $this->user->bank->type = Input::post("bank_type", 0);
             $this->user->bank->save();
             $is_chenged = true;
         }
     }
     $data["user"] = $this->user;
     $data["is_chenged"] = $is_chenged;
     $view = View::forge("teachers/profile", $data);
     $this->template->content = $view;
 }
Ejemplo n.º 20
0
 /**
  * Logic to deal with uploading the image file and generating thumbnails according to
  * what has been specified in the $thumbnails array.
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @param   bool   $loaded
  * @return  string|NULL
  */
 public function save($model, $value, $loaded)
 {
     $old_filename = $this->default;
     // Upload a file?
     if (is_array($value) and Upload::valid($value)) {
         if (FALSE !== ($filename = Upload::save($value, NULL, $this->path))) {
             // Chop off the original path
             $value = str_replace(realpath($this->path) . DIRECTORY_SEPARATOR, '', $filename);
             // Ensure we have no leading slash
             if (is_string($value)) {
                 $value = trim($value, DIRECTORY_SEPARATOR);
             }
             // delete the old file
             $file_has_changed = $old_filename != $this->default;
             if ($file_has_changed and file_exists(realpath($this->path) . DIRECTORY_SEPARATOR . $old_filename)) {
                 unlink(realpath($this->path) . DIRECTORY_SEPARATOR . $old_filename);
             }
             // generate any thumbnails
             $source_file = $this->path . DIRECTORY_SEPARATOR . $value;
             foreach ($this->thumbnails as $thumbnail) {
                 $dest_path = realpath($thumbnail['path']) . DIRECTORY_SEPARATOR;
                 // Delete the old file
                 if ($file_has_changed and file_exists($dest_path . $old_filename)) {
                     unlink($dest_path . $old_filename);
                 }
                 $image = Image::factory($source_file);
                 if (isset($thumbnail['rotation'])) {
                     $image->rotate($thumbnail['rotation']);
                 }
                 $w = $thumbnail['dest_w'];
                 $h = $thumbnail['dest_h'];
                 switch ($thumbnail['resize_type']) {
                     case Jelly_Field_Image::RESIZE_TYPE_CROP:
                         $image->crop($w, $h);
                         break;
                     case Jelly_Field_Image::RESIZE_TYPE_FIT:
                         if ($image->width > $w || $image->height > $h) {
                             $image->resize($w, $h);
                         }
                         break;
                     case Jelly_Field_Image::RESIZE_TYPE_EXACT_FIT:
                         $image->resize($w, $h, Image::INVERSE)->crop($w, $h);
                         break;
                     case Jelly_Field_Image::RESIZE_TYPE_NONE:
                         // Do nothing - copy of the image will be saved below
                         break;
                 }
                 $image->save($dest_path . $value);
             }
         } else {
             $value = $old_filename;
         }
     }
     return $value;
 }
Ejemplo n.º 21
0
 public function demo_account_update_profile_image()
 {
     if ($this->request->method() === 'POST') {
         $params = array('image' => Upload::save($_FILES['image'], NULL, '/tmp'));
         $api = Twitter::factory('account');
         $response = $api->update_profile_image($this->consumer, $this->token, $params);
         $this->content = Debug::vars($response);
     } else {
         $this->content = View::factory('demo/form')->set('uploads', TRUE)->set('message', 'Update your profile image.')->set('inputs', array('Image File' => Form::file('image')));
     }
 }
Ejemplo n.º 22
0
 protected function _process_file()
 {
     $file = $_FILES[$this->name()];
     if ($file = Upload::save($file, NULL, DOCROOT . $this->_upload_dir)) {
         $this->_uploaded = true;
         $file = str_replace(DOCROOT, "", $file);
         $this->_file_address = $file;
         return true;
     }
     return false;
 }
Ejemplo n.º 23
0
 public function save_as($filename, $dir = null)
 {
     $dir = self::upload_dir($dir);
     $ret = Upload::save($this->as_array(), $filename, $dir);
     if ($ret) {
         $this->_saved = $ret;
     } else {
         throw new Exception("Could not save file \"{$this->php_key}\" as \"{$filename}\".");
     }
     return $ret;
 }
Ejemplo n.º 24
0
 /**
  * CRUD controller: CREATE
  */
 public function action_create()
 {
     $this->auto_render = FALSE;
     $this->template = View::factory('js');
     if (!isset($_FILES['image'])) {
         $this->template->content = json_encode('KO');
         return;
     }
     $image = $_FILES['image'];
     if (core::config('image.aws_s3_active')) {
         require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
         $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
     }
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
         if (Upload::not_empty($image) and !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not valid format, please use one of this formats "%s"'), core::config('image.allowed_formats'))));
             return;
         }
         if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not of valid size. Size is limited to %s MB per image'), core::config('image.max_image_size'))));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
         return;
     } elseif ($image != NULL) {
         // saving/uploading img file to dir.
         $path = 'images/cms/';
         $root = DOCROOT . $path;
         //root folder
         $image_name = URL::title(pathinfo($image['name'], PATHINFO_FILENAME));
         $image_name = Text::limit_chars(URL::title(pathinfo($image['name'], PATHINFO_FILENAME)), 200);
         $image_name = time() . '.' . $image_name;
         // if folder does not exist, try to make it
         if (!file_exists($root) and !@mkdir($root, 0775, true)) {
             // mkdir not successful ?
             $this->template->content = json_encode(array('msg' => __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.')));
             return;
             // exit function
         }
         // save file to root folder, file, name, dir
         if ($file = Upload::save($image, $image_name, $root)) {
             // put image to Amazon S3
             if (core::config('image.aws_s3_active')) {
                 $s3->putObject($s3->inputFile($file), core::config('image.aws_s3_bucket'), $path . $image_name, S3::ACL_PUBLIC_READ);
             }
             $this->template->content = json_encode(array('link' => Core::config('general.base_url') . $path . $image_name));
             return;
         } else {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image file could not been saved.')));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
     }
 }
Ejemplo n.º 25
0
 public static function save_uploaded_image($image, $target_path)
 {
     if (Model_Image::validate_uploaded_image($image)) {
         if ($file = Upload::save($image, NULL, DOCROOT . "images/")) {
             Image::factory($file)->save($target_path);
             // Delete the temporary file
             unlink($file);
             return TRUE;
         }
     }
     return FALSE;
 }
Ejemplo n.º 26
0
 /**
  * грузим файлы аяксово
  */
 public function action_upload_image()
 {
     if (!empty($_FILES['file'])) {
         $name = explode('.', $_FILES['file']['name']);
         $filename = md5(time() . 'salt' . $_FILES['file']['name']) . '.' . end($name);
         $directory = Upload::generateImageDirectory($filename);
         if (Upload::save($_FILES['file'], $filename, $_SERVER["DOCUMENT_ROOT"] . $directory)) {
             $this->jsonResult(true, ['file' => $directory . $filename]);
         }
     }
     $this->jsonResult(false);
 }
Ejemplo n.º 27
0
 public function upload()
 {
     $arrFile = array();
     if ($_FILES['file_process_data']['name']) {
         if (\Upload::is_valid()) {
             \Upload::save();
             $fileName = current(\Upload::get_files());
             $arrFile['file_process_data'] = $fileName['saved_as'];
         }
     }
     return $arrFile;
 }
Ejemplo n.º 28
0
 private function afterUploaded(CUploadedFile $upload, $fileUrl, $fileType = UPLOAD_TYPE_UNKNOWN)
 {
     $key = param('sess_post_create_token');
     $postCreatetoken = app()->session[$key];
     $model = new Upload();
     $model->post_id = is_numeric($postCreatetoken) ? (int) $postCreatetoken : 0;
     $model->file_type = $fileType;
     $model->url = $fileUrl;
     $model->user_id = (int) user()->id;
     $model->token = $postCreatetoken;
     return $model->save();
 }
Ejemplo n.º 29
0
 public function save_cover($cover)
 {
     $new_name = bin2hex(openssl_random_pseudo_bytes(5));
     $cover['name'] = $new_name . '.' . pathinfo($cover['name'], PATHINFO_EXTENSION);
     $uploaddir = 'upload/covers/';
     if ($file = Upload::save($cover, NULL, $uploaddir)) {
         Image::factory($file)->save($uploaddir . $cover['name']);
         unlink($file);
         return $cover['name'];
     } else {
         return false;
     }
 }
Ejemplo n.º 30
0
 public static function newImg()
 {
     $img = Input::file('image');
     $temp = new Upload();
     if ($img) {
         $file = UploadService::post_upload();
         $temp->file = $file;
         $temp->thumb = $file;
         $temp->userId = Auth::user()->email;
         $temp->save();
         return $temp;
     }
 }