Exemple #1
0
 public function run()
 {
     DB::statement("TRUNCATE TABLE images");
     $image = new Picture();
     $image->image_path = 'asset/upload/D4C21840-5F68-48EA-A63E-7AC4C3D9B43A.JPG';
     $image->created_at = new DateTime();
     $image->updated_at = new DateTime();
     $image->big_path = 'asset/upload/D4C21840-5F68-48EA-A63E-7AC4C3D9B43A.JPG';
     $image->save();
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Picture();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Picture'])) {
         $model->attributes = $_POST['Picture'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->idpic));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemple #3
0
    Route::get('/list', 'ProductsController@display');
    Route::post('', ['as' => 'products.update', 'uses' => 'ProductsController@update']);
});
//Route::get('/image','ImageController@imageinsert');
//		Route::post('/image',['as' => 'images.store', 'uses' => 'ImageController@imagestore']);
//		Route::get('/imaged','ImageController@imageview');
Route::post('uploads', function () {
    $user = new Picture();
    $ued = Sentry::getUser()->id;
    $user->user_id = $ued;
    if ($image = Input::file('images')) {
        $filename = date('Y-m-d-H:i:s') . "-" . rand(1, 100);
        Image::make($image->getRealPath())->resize(150, 150)->save('public/images/' . $filename);
        $user->pic = 'images/' . $filename;
    } else {
        $user->pic = 'images/default.jpg';
    }
    if ($user->save()) {
        return 'passed';
    } else {
        return 'failed';
    }
});
Route::put('theme', function () {
    return View::make('homepage');
});
Route::get('/success', 'MailController@interested');
Route::group(['before' => 'auth|standardUser'], function () {
    Route::get('/payment', 'ZwitchController@payment');
    Route::post('/response', 'ZwitchController@response');
});
Exemple #4
0
 public function postUpload($model)
 {
     $input = Input::all();
     eerror_log(json_encode($input));
     $rules = array('file' => 'image|max:3000');
     $validation = Validator::make($input, $rules);
     if ($validation->fails()) {
         return Response::make($validation->errors->first(), 400);
     }
     $file = Input::file('file');
     $destinationPath = 'uploads/venues/' . $model->id;
     if (!file_exists($destinationPath)) {
         mkdir($destinationPath, 0777, true);
     }
     //$filename = str_random(12);
     $filename = date("d") . '-' . Str::random(8) . $file->getClientOriginalName();
     eerror_log(public_path() . '/' . $destinationPath . '/' . $filename);
     $pic_exists_fs = File::exists(public_path() . '/' . $destinationPath . '/' . $filename);
     $pic_exists_db = $model->pictures()->where('filename', '=', $filename)->whereNull('deleted_at')->first();
     if ($pic_exists_db || $pic_exists_fs) {
         return Response::json(['error' => 'error', 'reload' => false]);
     }
     $upload_success = Input::file('file')->move($destinationPath, $filename);
     $picture = new Picture();
     $picture->filename = $filename;
     $picture->user_id = Auth::user()->id;
     $picture->save();
     $model->pictures()->save($picture);
     if ($upload_success) {
         // Redirect to the blog posts management page
         return Response::json(['success' => 'success', 'reload' => true]);
     } else {
         return Response::json(['error' => 'error', 'reload' => false]);
     }
 }
 /**
  *保存图片页
  */
 public function ActionSavePicture()
 {
     //获取参数
     $city_id = isset($_GET['city_id']) ? $_GET['city_id'] : "";
     $create_thumbnails_pic = isset($_GET['create_thumbnails_pic']) ? $_GET['create_thumbnails_pic'] : "";
     $picture_category_id = isset($_GET['picture_category_id']) ? $_GET['picture_category_id'] : "";
     $picture_name = isset($_GET['picture_name']) ? $_GET['picture_name'] : "";
     $picture_title = isset($_GET['picture_title']) ? $_GET['picture_title'] : "";
     $picture_description = isset($_GET['picture_description']) ? $_GET['picture_description'] : "";
     //解析图片名称和扩展名
     $name_noext = substr($picture_name, 0, strrpos($picture_name, '.'));
     //名称(无扩展名)
     $name_ext = strrchr($picture_name, ".");
     //扩展名
     //将图片中文名称转换为拼音
     $name_noext_arr = IconvEncode::gbk2Pinyin($name_noext);
     $name_noext_pinyin = implode("", $name_noext_arr);
     //中、小图名称
     $picture_middle_name = $name_noext_pinyin . "_middle" . $name_ext;
     //中规格图名称
     $picture_samll_name = $name_noext_pinyin . "_samll" . $name_ext;
     //小规格图名称
     //获取图片类型
     $picture_category = PictureCategory::model()->findByPk($picture_category_id);
     if (isset($picture_category) && !empty($picture_category)) {
         if (isset($picture_category['PictureCategoryPinyin']) && !empty($picture_category['PictureCategoryPinyin'])) {
             //创建图片路径
             $pic_dir_path = IMAGES_PATH . $picture_category['PictureCategoryPinyin'] . '/' . date("Y-m") . '/';
             DirectoryFile::dirCreate($pic_dir_path);
             //大图上传
             $pic_big_src = $pic_dir_path . $name_noext_pinyin . $name_ext;
             //上传原始图片并生产规定格式的中图和小图
             file_put_contents($pic_big_src, file_get_contents('php://input'));
             //存放大图
             //图片信息存入数据库
             if (empty($picture_title)) {
                 $picture_title = $name_noext;
             }
             $picture_model = new Picture();
             $picture_model->CityId = $city_id;
             $picture_model->CategoryId = $picture_category_id;
             $picture_model->Name = $picture_name;
             $picture_model->Title = $picture_title;
             $picture_model->Description = $picture_description;
             $picture_model->save();
             //图片中、小图片路径保存到数据库
             $pic_id = $picture_model->attributes['ID'];
             if (isset($pic_id) && !empty($pic_id)) {
                 $picture_source['big'] = new PictureSource();
                 $picture_source['big']->PicId = $pic_id;
                 $picture_source['big']->PicSrc = $pic_big_src;
                 $picture_source['big']->SizeType = 0;
                 //原图
                 // 判断是否生成中、小图
                 if ($create_thumbnails_pic) {
                     $pic_middle_src = $pic_dir_path . $picture_middle_name;
                     $pic_small_src = $pic_dir_path . $picture_samll_name;
                     ImageChange::imgResize($pic_big_src, $pic_middle_src, 380, 210);
                     //生成中图
                     ImageChange::imgResize($pic_big_src, $pic_small_src, 180, 120);
                     //生成小图
                     $picture_source['middle'] = new PictureSource();
                     $picture_source['middle']->PicId = $pic_id;
                     $picture_source['middle']->PicSrc = $pic_middle_src;
                     $picture_source['middle']->SizeType = 1;
                     //中图
                     $picture_source['small'] = new PictureSource();
                     $picture_source['small']->PicId = $pic_id;
                     $picture_source['small']->PicSrc = $pic_small_src;
                     $picture_source['small']->SizeType = 2;
                     //小图
                 }
                 //事务[S]
                 $transaction = Yii::app()->db->beginTransaction();
                 //开启事务
                 try {
                     foreach ($picture_source as $pic_src) {
                         if (!$pic_src->save()) {
                             throw new Exception();
                         }
                     }
                     $transaction->commit();
                     //提交事务
                 } catch (Exception $e) {
                     $transaction->rollBack();
                     //回滚事务
                 }
                 //事务[S]
             }
             echo $pic_dir_path;
         }
     }
 }
Exemple #6
0
 public function test_for_multiple_hasone_and_belongsto()
 {
     $Altea = new Picture(array('title' => 'Altea Cupula de Mediterraneo, Costa Blanca'));
     $Altea->main_thumbnail->build(array('caption' => 'Altea'));
     $this->assertTrue($Altea->main_thumbnail->isNewRecord());
     $this->assertEqual($Altea->main_thumbnail->getType(), 'Thumbnail');
     $this->assertTrue($Altea->save());
     $this->assertFalse($Altea->main_thumbnail->isNewRecord());
     $Altea = new Picture(array('title' => 'Altea2'));
     $Altea->main_thumbnail->create(array('caption' => 'Altea2'));
     $this->assertFalse($Altea->main_thumbnail->isNewRecord());
     $this->assertEqual($Altea->main_thumbnail->getType(), 'Thumbnail');
     $this->assertTrue($Altea->save());
     $Altea = new Picture(array('title' => 'Altea3'));
     $Altea->main_thumbnail->assign(new Thumbnail(array('caption' => 'Altea3')));
     $this->assertTrue($Altea->main_thumbnail->isNewRecord());
     $this->assertEqual($Altea->main_thumbnail->getType(), 'Thumbnail');
     $this->assertTrue($Altea->save());
     $this->assertFalse($Altea->main_thumbnail->isNewRecord());
     $Altea->main_thumbnail->replace(new Thumbnail(array('caption' => '3rd Altea pic')));
     $this->assertFalse($Altea->main_thumbnail->isNewRecord());
     $Thumbnail = new Thumbnail();
     $this->assertFalse($Thumbnail->findFirstBy('caption', 'Altea3'));
     $Panorama = new Panorama(array('title' => 'Views from the old town'));
     $this->assertTrue($Panorama->save());
     $Panorama->thumbnail->build(array('caption' => 'Altea paronamic views from the Old town'));
     $this->assertEqual($Panorama->thumbnail->getType(), 'Thumbnail');
     $this->assertTrue($Panorama->thumbnail->isNewRecord());
     $this->assertTrue($Panorama->save());
     $this->assertFalse($Panorama->thumbnail->isNewRecord());
     $Thumbnail = new Thumbnail();
     $Thumbnail = $Thumbnail->findFirstBy('caption:has', 'Old town', array('include' => 'panorama'));
     $this->assertEqual($Thumbnail->panorama->title, 'Views from the old town');
 }
 public function postimage()
 {
     $image = Input::get('file');
     $selection = Input::get('selection');
     $exp = explode(",", $image);
     $data = base64_decode($exp[1]);
     $name = str_random(15);
     $tempfile = storage_path() . "/temp/" . $name . "";
     file_put_contents($tempfile, $data);
     $image_info = getImageSize($tempfile);
     switch ($image_info['mime']) {
         case 'image/gif':
             $extension = '.gif';
             break;
         case 'image/jpeg':
             $extension = '.jpg';
             break;
         case 'image/png':
             $extension = '.png';
             break;
         default:
             // handle errors
             break;
     }
     // open file a image resource
     $img = Image::make($tempfile);
     $img->save($tempfile);
     $large = Image::make($tempfile)->resize(210, 210)->save(storage_path() . "/pictures/" . $name . "-large" . $extension);
     $medium = Image::make($tempfile)->resize(50, 50)->save(storage_path() . "/pictures/" . $name . "-medium" . $extension);
     $small = Image::make($tempfile)->resize(22, 22)->save(storage_path() . "/pictures/" . $name . "-small" . $extension);
     unlink($tempfile);
     $pic = new Picture();
     $pic->name = $name;
     $pic->user = Auth::user()->id;
     $pic->extension = $extension;
     $pic->save();
     return Response::json(['id' => $pic->id, 'success' => true]);
 }
Exemple #8
0
 public function uploadImage()
 {
     if (!Auth::check()) {
         return Response::json(array('errCode' => 1, 'message' => '请登录'));
     }
     $img_urls = Input::get('img_urls');
     $album_id = Input::get('album_id');
     $validation = Validator::make(array('img_urls' => $img_urls), array('img_urls' => 'required'));
     if ($validation->fails()) {
         return Response::json(array('errCode' => 2, 'message' => '上传信息不完整!'));
     }
     foreach ($img_urls as $img_url) {
         $picture = new Picture();
         $picture->picture = $img_url;
         $picture->album_id = $album_id;
         if (!$picture->save()) {
             return Response::json(array('errCode' => 3, 'message' => '相片上传失败!'));
         }
     }
     return Response::json(array('errCode' => 0, 'message' => '上传成功!'));
 }
 /**
  * Handle hub form (add/edit)
  *
  * @return Response
  */
 public function post_hub()
 {
     $hub = null;
     if (Input::has('id')) {
         $hub = Hub::find(Input::get('id'));
     }
     if (is_null($hub)) {
         $hub = new Hub();
     }
     $geo = Geocoder::getCoordinatesForQuery(Input::get('location'));
     $hub->name = Input::get('name');
     $hub->description = Input::get('description');
     $hub->location = Input::get('location');
     $hub->facebook = Input::get('facebook');
     $hub->google = Input::get('google');
     $hub->twitter = Input::get('twitter');
     $hub->slug = Str::slug($hub->name);
     if ($geo != 'NOT_FOUND') {
         $hub->lat = $geo['lat'];
         $hub->lng = $geo['lng'];
     }
     if (Input::has('art')) {
         $image = Input::get('art');
         $exp = explode(",", $image);
         $name = str_random(15);
         $data = base64_decode($exp[1]);
         $tempfile = storage_path() . "/temp/" . $name . "";
         file_put_contents($tempfile, $data);
         Image::make($tempfile)->resize(210, 210)->save(storage_path() . "/pictures/" . $name . ".png");
         unlink($tempfile);
         $p = new Picture();
         $p->name = $name;
         $p->user = 0;
         $p->extension = '.png';
         $p->save();
         $hub->picture = $p->id;
     }
     $hub->save();
     return Redirect::to('admin/hubs');
 }
Exemple #10
0
 /**
  * Creates a new picture in database.
  * Used in /photoalbum/actions/executeRefreshPhotoAlbum
  *
  * @param PhotoAlbum $photoalbum_object ex: PhotoAlbum(Alemania)
  * @param Array $picture_info[] ex: [IMG_32, 2010x4000, jpg, 4,32 MB]
  * @return Picture
  */
 public static function createPicture($photoalbum_object, $picture_info, $photoalbum_folder, $picture_filename, $user)
 {
     //looking for this episode in db
     $picture_object = NULL;
     $settings = Doctrine_Core::getTable('Settings')->findOneByUserId($user);
     foreach ($photoalbum_object['Pictures'] as $picture) {
         if ($picture->title == $picture_info['title']) {
             $picture_object = $picture;
         }
     }
     //if there is no picture
     if ($picture_object == NULL) {
         $picture_object = new Picture();
         $picture_object->title = $picture_info['title'];
     }
     $picture_object->filesize = $picture_info['filesize'];
     $picture_object->fileformat = $picture_info['fileformat'];
     $picture_object->dimensions = $picture_info['dimensions'];
     $picture_object->file_abs = utf8_encode($picture_info['file_abs']);
     $picture_object->file_rel = utf8_encode($picture_info['file_rel']);
     $picture_object->thumbnail_abs = Util::makePath(array($settings['photoalbums_root'], utf8_encode($photoalbum_folder), 'thumbs', $picture_filename));
     $picture_object->thumbnail_rel = Util::changePathSeparators(Util::makePath(array($settings['photoalbums_root_rel'], utf8_encode($photoalbum_folder), 'thumbs', $picture_filename)));
     //create thumbnail
     if (!file_exists($picture_object['thumbnail_abs'])) {
         if (!file_exists(Util::makePath(array($settings['photoalbums_root'], $photoalbum_folder, 'thumbs')))) {
             mkdir(Util::makePath(array($settings['photoalbums_root'], $photoalbum_folder, 'thumbs')));
         }
         $dimensions = array();
         $dimensions = explode('x', $picture_info['dimensions']);
         if ($dimensions[0] > $dimensions[1]) {
             $thumbnail = new sfThumbnail(155, 120, false, false, 100);
         } else {
             $thumbnail = new sfThumbnail(120, 155, false, false, 100);
         }
         if (file_exists($picture_info['file_abs'])) {
             $thumbnail->loadFile($picture_info['file_abs']);
             //Creating thumbnail image
             $thumbnail->save($picture_object['thumbnail_abs'], 'image/jpeg');
             chmod($picture_object['thumbnail_abs'], 0777);
         }
     }
     $picture_object->save();
     $photoalbum_object->Pictures[] = $picture_object;
     $photoalbum_object->save();
     return $picture_object;
 }
 /**
  * Action: postUpload
  * @param  int $id post ID
  * @return response
  */
 public function postUpload($id)
 {
     $input = Input::all();
     $rules = array('file' => 'image|max:3000');
     $validation = Validator::make($input, $rules);
     if ($validation->fails()) {
         return Response::make($validation->errors->first(), 400);
     }
     $file = Input::file('file');
     $destinationPath = 'uploads/articles/';
     $ext = $file->guessClientExtension();
     // Get real extension according to mime type
     $fullname = $file->getClientOriginalName();
     // Client file name, including the extension of the client
     $hashname = date('H.i.s') . '-' . md5($fullname) . '.' . $ext;
     // Hash processed file name, including the real extension
     $picture = Image::make($file->getRealPath());
     // crop the best fitting ratio and resize image
     $picture->fit(1024, 683)->save(public_path($destinationPath . $hashname));
     $models = new Picture();
     $models->filename = $hashname;
     $models->article_id = $id;
     $models->user_id = Auth::user()->id;
     if ($models->save()) {
         return Response::json('success', 200);
     } else {
         return Response::json('error', 400);
     }
 }