/** *新的的话就要新建一个guide,旧的的话就是要将photo直接保存即可 */ public function savePhoto(Photo &$photo) { if ($this->isNewRecord) { $this->title = Scenic::model()->findByPk($photo->scenicId); $this->userId = Yii::app()->user->userId; $this->save(); $photo->guideId = $this->guideId; $photo->save(); } else { if ($photo->save()) { $this->save(); } } }
public function saveCreate() { $input = Input::all(); $task = new Photo(); $task->title = $input['title']; $task->description = $input['description']; $task->category = $input['category']; // $task->path = base_path() . '/public/uploads/' . $input['image']->getClientOriginalName(); // getting the name of the image $filename = time() . $input['image']->getClientOriginalName(); //attaching the image name with the src path and save to path $task->path = 'uploads/' . $filename; //before the image is moved to the uploads folder we resize with intervention $background = Image::canvas(650, 650); $image = Input::file('image'); $newimage = Image::make($image)->resize(650, 650, function ($c) { $c->aspectRatio(); $c->upsize(); }); $background->insert($newimage, 'center'); //moving the image to the uploads folder $savepath = 'public/uploads'; $background->save(base_path() . '/public/uploads/' . $filename); $task->save(); return Redirect::action('HomeController@home'); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Photo(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Photo'])) { $model->attributes = $_POST['Photo']; if (isset($_FILES['images']['name'][0]) && $_FILES['images']['name'][0] !== '') { $model->name = 'new'; } if ($model->validate()) { $images = CUploadedFile::getInstancesByName('images'); foreach ($images as $image) { $imageModel = new Photo(); $name = uniqid() . $image->name; $image->saveAs(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . $name); copy(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . $name, Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $name); $thumb = Yii::app()->image->load(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $name); $thumb->resize(300, 300); $thumb->save(); $imageModel->name = $name; $imageModel->category_id = $_POST['Photo']['category_id']; $imageModel->save(); } Yii::app()->user->setFlash('success', Yii::t('main', 'Данные успешно сохранены!')); $this->refresh(); } else { Yii::app()->user->setFlash('error', Yii::t('main', 'Ошибка!')); } } $this->render('create', array('model' => $model)); }
public function __construct() { gateKeeper(); $user = getLoggedInUser(); $user->createAvatar(); if (isEnabledPlugin("photos")) { $album = getEntity(array("type" => "Photoalbum", "metadata_name_value_pairs" => array(array("name" => "owner_guid", "value" => getLoggedInUserGuid()), array("name" => "title", "value" => "Profile Avatars")))); $photo = new Photo(); $photo->owner_guid = getLoggedInUserGuid(); $photo_guid = $photo->save(); Image::copyAvatar($user, $photo); $photo = getEntity($photo_guid); if (!$album) { $album = new Photoalbum(); $album->owner_guid = getLoggedInUserGuid(); $album->title = "Profile Avatars"; $album_guid = $album->save(); $album = getEntity($album_guid); Image::copyAvatar($photo, $album); } $photo->container_guid = $album->guid; $photo->save(); } runHook("action:edit_avatar:after", array("user" => $user)); new Activity(getLoggedInUserGuid(), "activity:avatar:updated", array($user->getURL(), $user->full_name)); new SystemMessage("Your avatar has been uploaded."); forward("profile/" . $user->guid); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $imageName = ''; $imagePath = public_path() . '/img/'; if (Input::hasFile('photo')) { $img = Input::file('photo'); $imageName = str_random(6) . '_' . $img->getClientOriginalName(); $img->move($imagePath, $imageName); $img = Image::make($imagePath . $imageName); $img->save($imagePath . $imageName); $thumb = Image::make($imagePath . $imageName); $thumbName = $imageName; $thumbPath = public_path() . '/thumbs/img/'; $thumb->resize(100, 100); $thumb->save($thumbPath . $thumbName); $imgEntry = new Photo(); $imgEntry->user_id = Auth::user()->id; $imgEntry->caption = Input::get('caption'); $imgEntry->path = 'img/' . $imageName; $imgEntry->save(); return Response::json(array('error' => false, 'message' => 'Upload successful.'), 200); } else { return Response::json(array('error' => 'true', 'photos' => null), 200); } }
public function __construct() { $editor = getInput("editor_id"); if (file_exists($_FILES['avatar']['tmp_name'])) { // Check if General album exists $album = getEntity(array("type" => "Photoalbum", "metadata_name_value_pairs" => array(array("name" => "owner_guid", "value" => getLoggedInUserGuid()), array("name" => "title", "value" => "General")))); $photo = new Photo(); $photo->owner_guid = getLoggedInUserGuid(); $photo->save(); $photo->createAvatar(); if (!$album) { $album = new Photoalbum(); $album->title = "General"; $album->owner_guid = getLoggedInUserGuid(); $album->access_id = "public"; Image::copyAvatar($photo, $album); $album->save(); } $photo->container_guid = $album->guid; if (!$album->title != "Profile Avatars" && $album->title != "General") { new Activity(getLoggedInUserGuid(), "activity:add:photo", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $album->getURL(), $album->title, "<a href='" . $album->getURL() . "'>" . $photo->icon(EXTRALARGE, "img-responsive") . "</a>"), $album->access_id); } $photo->save(); forward(false, array("insertphoto" => $photo->guid, "editor" => $editor)); } else { forward(); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $id = Auth::user()->ID; $files = Input::file('files'); $assetPath = '/uploads/' . $id; $uploadPath = public_path($assetPath); $results = array(); foreach ($files as $file) { if ($file->getSize() > $_ENV['max_file_size']) { $results[] = array("name" => $file->getClientOriginalName(), "size" => $file->getSize(), "error" => "Please upload file less than " . $_ENV['max_file_size'] / 1000000 . "mb"); } else { //rename filename so that it won't overlap with existing file $extension = $file->getClientOriginalExtension(); $filename = time() . Str::random(20) . "." . $extension; // store our uploaded file in our uploads folder $name = $assetPath . '/' . $filename; $photo_attributes = array('name' => $filename, 'size' => $file->getSize(), 'url' => asset($name), 'user_id' => $id); $photo = new Photo($photo_attributes); if ($photo->save()) { if (!is_dir($uploadPath)) { mkdir($uploadPath, 0777); } //resize image into different sizes foreach (Photo::getThumbnailSizes() as $key => $thumb) { Image::make($file->getRealPath())->resize($thumb['width'], $thumb['height'])->save($uploadPath . "/" . $key . "-" . $filename); } //save original file $file->move($uploadPath, $filename); $results[] = Photo::find($photo->id)->find_in_json(); } } } // return our results in a files object return json_encode(array('files' => $results)); }
public function post_new_city() { $rules = array('city' => 'required|unique:photos', 'picture' => 'required'); $v = Validator::make(Input::all(), $rules); if ($v->fails()) { return Redirect::to('admin/cityphotos')->with_errors($v)->with_input(); } else { $new_photo = array('city' => ucwords(Input::get('city'))); $photo = new Photo($new_photo); if ($photo->save()) { $upload_path = path('public') . Photo::$upload_path_city . $photo->city; if (!File::exists($upload_path)) { File::mkdir($upload_path); } $filename = $photo->city . '.jpg'; $path_to_file = $upload_path . '/' . $filename; $dynamic_path = '/' . Photo::$upload_path_city . $photo->city . '/' . $filename; $success = Resizer::open(Input::file('picture'))->resize(1024, 724, 'auto')->save($path_to_file, 75); if ($success) { $new_photo = Photo::find($photo->id); $new_photo->location = $dynamic_path; $new_photo->save(); } return Redirect::to('admin/cityphotos')->with('msg', '<div class="alert alert-success"><strong>City foto is geupload!</strong></div>'); } else { return Redirect::to('admin/cityphotos')->with('msg', '<div class="alert alert-error"><strong>Er is iets mis gegaan bij het toevoegen.</strong></div>'); } } }
public function addPost() { // let's setup some rules for our new data // I'm sure you can come up with better ones $rules = array('title' => 'required|min:3|max:128', 'file' => 'mimes:jpg,gif,png'); $pictrue = ''; $title = Input::get('title'); $description = Input::get('description'); $author_id = Input::get('author_id'); $tags = Input::get('tags'); if (Input::hasFile('file')) { $file = Input::file('file'); $ext = $file->guessClientExtension(); $filename = $file->getClientOriginalName(); $file->move(public_path() . '/data', md5(date('YmdHis') . $filename) . '.' . $ext); $pictrue = md5(date('YmdHis') . $filename) . '.' . $ext; } $new_photo = array('title' => $title, 'description' => $description, 'author_id' => $author_id, 'views' => 0, 'pictrue' => $pictrue, 'tags' => $tags); $v = Validator::make($new_photo, $rules); if ($v->fails()) { // redirect back to the form with // errors, input and our currently // logged in user return Redirect::to('photo/add')->with('user', Auth::user())->withErrors($v)->withInput(); } // create the new post $photo = new Photo($new_photo); $photo->save(); // redirect to viewing our new post return Redirect::to('photo/view/' . $photo->id); }
public function post_new() { $rules = array('title' => 'required|min:5|max:128', 'street' => 'required', 'postalcode' => 'required|match:#^[1-9][0-9]{3}\\h*[A-Z]{2}$#i', 'city' => 'required', 'type' => 'required', 'surface' => 'required|integer', 'price' => 'required|numeric|max:1500|min:100', 'date' => 'required|after:' . date('d-m-Y'), 'pictures' => 'required|image|max:3000', 'register' => 'required', 'email' => 'required|email|same:email2', 'description' => 'required|min:30', 'captchatest' => 'laracaptcha|required', 'terms' => 'accepted'); $v = Validator::make(Input::all(), $rules, Room::$messages); if ($v->fails()) { return Redirect::to('kamer-verhuren')->with_errors($v)->with('msg', '<div class="alert alert-error"><strong>Verplichte velden zijn niet volledig ingevuld</strong><br />Loop het formulier nogmaals na.</div>')->with_input(); } else { if (Auth::check()) { $status = 'publish'; } else { $status = 'pending'; } $new_room = array('title' => ucfirst(Input::get('title')), 'street' => ucwords(Input::get('street')), 'housenr' => Input::get('housenr'), 'postalcode' => Input::get('postalcode'), 'city' => ucwords(Input::get('city')), 'type' => Input::get('type'), 'surface' => Input::get('surface'), 'price' => Input::get('price'), 'available' => date("Y-m-d", strtotime(Input::get('date'))), 'gender' => Input::get('gender'), 'pets' => Input::get('pets'), 'smoking' => Input::get('smoking'), 'toilet' => Input::get('toilet'), 'shower' => Input::get('shower'), 'kitchen' => Input::get('kitchen'), 'register' => Input::get('register'), 'social' => Input::get('social'), 'email' => strtolower(Input::get('email')), 'description' => ucfirst(Input::get('description')), 'status' => $status, 'url' => Str::slug(Input::get('city')), 'delkey' => Str::random(32, 'alpha'), 'del_date' => date('y-m-d', strtotime('+2 months'))); $room = new Room($new_room); if ($room->save()) { $upload_path = path('public') . Photo::$upload_path_room . $room->id; if (!File::exists($upload_path)) { File::mkdir($upload_path); chmod($upload_path, 0777); } $photos = Photo::getNormalizedFiles(Input::file('pictures')); foreach ($photos as $photo) { $filename = md5(rand()) . '.jpg'; $path_to_file = $upload_path . '/' . $filename; $dynamic_path = '/' . Photo::$upload_path_room . $room->id . '/' . $filename; $success = Resizer::open($photo)->resize(800, 533, 'auto')->save($path_to_file, 80); chmod($path_to_file, 0777); if ($success) { $new_photo = new Photo(); $new_photo->location = $dynamic_path; $new_photo->room_id = $room->id; $new_photo->save(); } } Message::send(function ($message) use($room) { $message->to($room->email); $message->from('*****@*****.**', 'Kamergenood'); $message->subject('In afwachting op acceptatie: "' . $room->title . '"'); $message->body('view: emails.submit'); $message->body->id = $room->id; $message->body->title = $room->title; $message->body->price = $room->price; $message->body->type = $room->type; $message->body->surface = $room->surface; $message->body->available = $room->available; $message->body->description = $room->description; $message->body->url = $room->url; $message->body->delkey = $room->delkey; $message->html(true); }); if (Message::was_sent()) { return Redirect::to('kamer-verhuren')->with('msg', '<div class="alert alert-success"><strong>Hartelijk dank voor het vertrouwen in Kamergenood!</strong> De kameradvertentie zal binnen 24 uur worden gecontroleerd en geplaatst.</div>'); } } else { return Redirect::to('kamer-verhuren')->with('msg', '<div class="alert alert-error"><strong>Er is iets mis gegaan bij het toevoegen.</strong> Probeer het later nog eens.</div>')->with_input(); } } }
public function testInsert() { $photo = new Photo(); $photo->attributes = $_POST['Photo']; if ($photo->save()) { $this->photo_id = $photo->id; $this->assertEquals($_POST['Photo'], $photo->attributes); } }
function fetch($annee = NULL) { if (!$this->activite) { return array('activites' => $this->unite->findActivites($annee)); } else { $this->controller->assert(null, $this->activite, 'envoyer-photo', "Vous n'avez pas le droit d'envoyer de photo de " . $this->activite->getIntituleComplet() . "."); } $m = new Wtk_Form_Model('envoyer'); $i = $m->addString('titre', 'Titre'); $m->addConstraintRequired($i); $m->addFile('photo', "Photo"); $m->addString('commentaire', 'Votre commentaire'); $m->addBool('envoyer', "J'ai d'autres photos à envoyer", true); $m->addNewSubmission('envoyer', "Envoyer"); $t = new Photos(); if ($m->validate()) { $p = new Photo(); $p->titre = $m->titre; $p->slug = $t->createSlug(wtk_strtoid($m->titre)); $p->activite = $this->activite->id; $action = $m->envoyer ? 'envoyer' : 'consulter'; $c = new Commentaire(); $c->auteur = Zend_Registry::get('individu')->id; $c->message = $m->commentaire; $db = $t->getAdapter(); $db->beginTransaction(); try { $c->save(); $p->commentaires = $c->id; $p->save(); $i = $m->getInstance('photo'); if ($i->isUploaded()) { $tmp = $i->getTempFilename(); $p->storeFile($tmp); } $url = $this->controller->_helper->Url('voir', 'photos', null, array('photo' => $p->slug), true); $this->controller->logger->info("Photo envoyée", $url); foreach ($this->activite->findUnitesParticipantesExplicites() as $u) { $ident = new Identification(); $ident->photo = $p->id; $ident->unite = $u->id; $ident->save(); $this->controller->logger->info("Unité identifiée sur une photo", $url); } $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $this->controller->_helper->Flash->info("Photo envoyée"); $this->controller->redirectSimple($action, null, null, array('album' => $this->activite->slug)); } $photos = $this->activite->findPhotos($t->select()->order('date')); return array('unite' => $this->unite, 'annee' => $annee, 'model' => $m, 'activite' => $this->activite, 'photos' => $photos); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Photo(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Photo'])) { $model->attributes = $_POST['Photo']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Añade datos de la ultima foto cargda (Zend_Gdata_Photos_PhotoFeed) * al modelo Photo. * * @return Photo */ public static function converseToModel() { $picasa = new Neo_Gdata_Photo(); $photo = $picasa->getLastPhotoUpload(); $foto = new Photo(); $foto->photo_id = $photo->getGphotoId(); $foto->titulo = $photo->getTitle(); $foto->descripcion = $photo->getMediaGroup()->getDescription(); $thumbnail = $photo->getMediaGroup()->getThumbnail(); $foto->thumbnail_1 = $thumbnail[0]->getUrl(); $foto->thumbnail_2 = $thumbnail[1]->getUrl(); $foto->thumbnail_3 = $thumbnail[2]->getUrl(); $foto->save(); return $foto; }
public function addPhoto($userId, $filePath) { $photo = new Photo(); $photo->user_id = $userId; $photo->photo_album_id = $this->id; $photo->file_path = $filePath; $saved = $photo->save(); if ($saved) { if (count($this->photos) === 1) { $this->saveAttributes(array('cover_photo_id' => $photo->id)); } return $photo; } return null; }
/** * Create images for this article. */ public function createImage() { $thumb = Yii::app()->phpThumb->create($this->image->getTempName()); $thumb->resize(600, 600); $path = Yii::app()->params['projectPath'] . Yii::app()->params['imagePath']; $thumb->save($path . $this->imageName . '.jpg', 'jpg'); // Add this image to the db. $pic = new Photo(); $pic->Name = $this->imageName . '.jpg'; if ($pic->save()) { // Create new linker. $picLinker = new PlantLeafPhoto(); $picLinker->PlantLeafId = $this->Id; $picLinker->PhotoId = $pic->Id; $picLinker->save(); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aProduct !== null) { if ($this->aProduct->isModified() || $this->aProduct->isNew()) { $affectedRows += $this->aProduct->save($con); } $this->setProduct($this->aProduct); } if ($this->aPhoto !== null) { if ($this->aPhoto->isModified() || $this->aPhoto->isNew()) { $affectedRows += $this->aPhoto->save($con); } $this->setPhoto($this->aPhoto); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = ProductHasPhotoPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setNew(false); } else { $affectedRows += ProductHasPhotoPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
public static function toBase($contractor_id = false) { if (isset($_POST['Service'])) { if ($contractor_id) { $_POST['Service']['contractor_id'] = $contractor_id; } $service_id = SaveData::model('Service', $_POST['Service']); /* сохраняем картинки */ $photo_names = UploadFile::saves('Service', $service_id, 'service-photo'); foreach ($photo_names as $photo_name) { if ($photo_name) { $tPhoto = new Photo(); $tPhoto->src = $photo_name; $tPhoto->service_id = $service_id; $tPhoto->save(); } } return $service_id; } return false; }
public function executeUpload(sfWebRequest $request) { $result = 'All broken :('; try { //@todo: added CSRF check; $files = $request->getFiles(); $fileData = array_pop($files); $validator = new sfValidatorFile(array('max_size' => 1024 * 1024, 'mime_types' => array('image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif', 'application/octet-stream'))); $file = $validator->clean($fileData); $file instanceof sfValidatedFile; $uploader = new ImageUploader(); $uploaded = $uploader->login()->upload($file->getTempName()); $photo = new Photo(); $photo->name = $uploaded->image; $photo->thumb = $uploaded->thumb; $photo->save(); $result = array('id' => $photo->getId(), 'image' => $uploaded->image, 'thumb' => $uploaded->thumb); } catch (Exception $e) { $result = $e->getMessage(); } return $this->renderText(json_encode($result)); }
/** * Копирует аватар пользователя из Vkontakte в систему */ protected function _copyAvatar($avatarUrl) { //Читаем картинку и сохраняем в jpeg в нужную дирректорию $im = @imagecreatefromjpeg($avatarUrl); //JPEG: if ($im == false) { $im = @imagecreatefromgif($avatarUrl); } //GIF if ($im == false) { $im = @imagecreatefrompng($avatarUrl); } //png if ($im == false) { return; } // Определяем мета-данные картинки $usersService = ZendExtra_Controller_Action_Helper_Service::get('Users', 'users'); $user = $usersService->getCurrentUser(); $defaultService = ZendExtra_Controller_Action_Helper_Service::get('Default', 'default'); $extension = $defaultService->getExtensionFromUrl($avatarUrl); $imageData = array('user_id' => $user['id'], 'object_type' => ObjectToItem::OBJECT_TYPE_USER, 'object_id' => $user['id'], 'width' => imagesx($im), 'height' => imagesy($im), 'mime_type' => $defaultService->getMimeTypeFromExtension($extension), 'type' => Photo::TYPE_AVATAR); $image = new Photo(); $image->fromArray($imageData); if ($image->save() != FALSE) { return false; } // Копируем картинку $savePath = ROOT_PATH . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'pictures' . DIRECTORY_SEPARATOR . ObjectToItem::OBJECT_TYPE_USER . DIRECTORY_SEPARATOR . $image['id'] . '.' . $extension; if (!imagejpeg($im, $savePath)) { ImageDestroy($im); $image->delete(); return false; } ImageDestroy($im); return true; }
public function post_upload() { $input = Input::all(); if (isset($input['description'])) { $input['description'] = filter_var($input['description'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES); } $rules = array('photo' => 'required|image|max:500', 'title' => 'required', 'album' => 'required'); $v = Validator::make($input, $rules); if ($v->fails()) { return Redirect::to('profile')->with_errors($v); } $extension = $input['photo']->guessExtension(); $directory = public_path() . '\\uploads'; $filename = sha1(Auth::user()->id . time()) . ".{$extension}"; $upload_success = $input['photo']->move($directory, $filename); if ($upload_success) { $photo = new Photo(['title' => $input['title'], 'img_name' => $filename, 'author_id' => Auth::user()->id, 'album_id' => $input['album']]); $photo->save(); Session::flash('status_success', 'You have successfully uploaded your new pic!'); } else { Session::flash('status_error', 'An error has occured while uploading your pic -- Please Try Again!'); } return Redirect::to('/albums/' . $photo->album_id); }
$upload_ok = 0; } // Allow certain file formats if ($image_file_type != "jpg" && $imageFileType != "jpeg") { $_SESSION["errormsg"] = "Sorry, only JPEG is allowed."; $upload_ok = 0; } // Make sure user filled out a desciption if ($_POST['caption'] == null) { $_SESSION['errormsg'] = "You must fill out a caption."; $uploadOk = 0; } if ($upload_ok == 1) { $photo->setImageFile(); $photo->caption = $_POST['caption']; $photo->save(); } else { echo $_SESSION["errormsg"]; } ?> <html> <head> <meta charset="UTF-8"> <title>Test Photo</title> </head> <body> <h1>Photo Uploaded</h1> <pre> <h2>Caption</h2> <?php
public static function recordImageBy($type_name, $type_id) { try { $check = Photo::where('type_name', $type_name)->where('type_id', $type_id)->count(); if ($check == 1) { $getId = Photo::where('type_name', $type_name)->where('type_id', $type_id)->get(); $update = Photo::find($getId[0]->id); $update->name = $name; $update->type_name = $type_name; $update->type_id = $type_id; $update->status = 1; $update->save(); } else { $post = new Photo(); $post->name = $name; $post->type_name = $type_name; $post->type_id = $type_id; $post->status = 1; $post->save(); } return "ok"; } catch (Exception $e) { return "no"; } }
<?php if (!$session->is_signed_in()) { redirect('login.php'); } ?> <?php $message = ""; if (isset($_FILES['file'])) { // on utilise le isset($_FILES['file']) à la place de isset($_POST['submit']) pour que le multi upload fonctionne $photo = new Photo(); $photo->title = $_POST['title']; $photo->description = $_POST['description']; $photo->set_file($_FILES['file']); if ($photo->save()) { $message = "Photo successfully uploaded"; } } ?> <!-- Navigation --> <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <!--Top menu --> <?php include "includes/top_nav.php"; ?> <!--SideBar --> <?php include "includes/side_nav.php"; ?> </nav>
public function fetchProxyContents($contents) { foreach ($contents as $weibo) { $oldPhoto = $this->findByAttributes(array('weibo_id' => $weibo->weibo_id)); if ($oldPhoto) { continue; } // Fetch Image $filename = $this->fetchProxyImage(Yii::app()->params['proxyServer'] . $weibo->image, $weibo->weibo_id); if ($filename) { $photo = new Photo(); $photo->weibo_id = $weibo->weibo_id; $photo->url = $weibo->url; $photo->image = $filename; $photo->screen_name = $weibo->screen_name; $photo->sns_uid = $weibo->sns_uid; $photo->gender = $weibo->gender; $photo->location = $weibo->location; $photo->avatar = $weibo->avatar; $photo->content = $weibo->content; $photo->status = 0; $photo->datetime = time(); $photo->save(); } } }
public function actiongoPhotoFB() { ignore_user_abort(1); set_time_limit(0); $urlPhoto = $_POST['urlPhoto']; $f = $_POST['filter']; $capPhoto = $_POST['capPhoto']; Helper::debugConsole("post ok"); $namePhoto = Helper::getLastPath($urlPhoto); $min_rand = rand(0, 1000); $max_rand = rand(100000000000, 10000000000000000); $name_file = rand($min_rand, $max_rand); //this part is for creating random name for image $ext = end(explode(".", $namePhoto)); //gets extension $file = Yii::app()->request->baseUrl . "photo/" . $name_file . "." . $ext; // Save Photo From Facebook And Add Filter Helper::save_image($urlPhoto, $file); $filter = Instagraph::factory($file, $file); $filter->{$f}(); Helper::debugConsole("Save Photo From Facebook And Add Filter ok"); // 320 Show Preview $immid = new Imagick($file); if ($immid->getimagewidth() > 320) { $immid->thumbnailImage(320, null); $immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext); $immid->destroy(); chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777); } else { $immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext); $immid->destroy(); chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777); } Helper::debugConsole("320 Show Preview ok"); // null x 230 show last upload $imlast = new Imagick($file); $imlast->thumbnailimage(null, 230); $imlast->writeImage(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext); $imlast->destroy(); chmod(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext, 0777); Helper::debugConsole("null x 230 show last upload ok"); // 130 x 110 thumbmail $im = new Imagick($file); $im->thumbnailImage(130, 110); $im->writeImage(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext); chmod(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext, 0777); $im->destroy(); Helper::debugConsole("130 x 110 thumbmail ok"); $photo = new Photo(); $photo->link = $file; $photo->fbid = Yii::app()->facebook->getUser(); $photo->ip = $_SERVER['REMOTE_ADDR']; Helper::debugConsole("set data ok"); if ($photo->save()) { $id = $photo->id; $cr = "\n" . "http://www.pla2gram.com/?p=" . $id . "&theater=1"; $capFB = $capPhoto . $cr; Helper::debugConsole("set fb ok"); // Post to Facebook $args = array('message' => $capFB); $args['image'] = '@' . realpath($file); Yii::app()->facebook->api('/me/photos', 'post', $args); Helper::debugConsole("save fb ok"); Helper::redir("/?p=" . $id, 0); } else { print_r($photo->getErrors()); } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Books'])) { $model->attributes = $_POST['Books']; if (isset($_POST['Autor'])) { $model->autor = $_POST['Autor']; } if ($model->saveWithRelated(array('autor' => array('scenario' => 'special')))) { if (isset($_FILES['Photo']['tmp_name'])) { foreach ($_FILES['Photo']['tmp_name'] as $idPhoto => $photoEach) { if (!empty($photoEach['image'])) { $rnd = rand(0, 9999); $name = $rnd . $_FILES['Photo']['name'][$idPhoto]['image']; move_uploaded_file($photoEach['image'], 'images/books/' . $name); $photo = new Photo(); $photo->books_id = $model->id; $photo->name = $name; $photo->save(); } } } $this->redirect(array('admin')); } else { $model->addError('autor', 'Error occured while saving autor.'); } } $this->render('update', array('model' => $model)); }
/** * Update the specified resource in storage. * PUT /articles/{slug} * * @param int $slug * @return Response */ public function update($slug) { $thumbPath = Input::get('thumbPath'); $thumbId = Input::get('thumbId'); $image = Input::file('image'); $article = Article::where('slug', $slug)->first(); $article->title = Input::get('title'); $article->body = Input::get('body'); $article->category_id = Input::get('category_id'); $article->save(); if ($image) { File::delete($thumbPath); $file = Photo::where('id', $thumbId)->delete(); $thumb = new Photo(); $image = Input::file('image'); $filename = time() . '-' . $image->getClientOriginalName(); $destinationPath = public_path('thumbs/' . $filename); $a = Image::make($image->getRealPath())->fit(1280, 720)->save($destinationPath, 50); // SAVE TO DB $thumb->image = 'thumbs/' . $filename; $thumb->article_id = $article->id; $thumb->save(); return Redirect::to('/dashboard')->with('message', 'Thumbnail updated successfully'); } else { return Redirect::to('/dashboard')->with('message', 'Article Updated successfully'); } // return View::make('admin.home')->withMessage('Article Saved!'); }
public function actionAddphotos($phid) { $model = Photogallery::model()->findByPk($phid); if (isset($_POST['savebutton'])) { $criteria = new CDbCriteria(); $criteria->order = 'pos DESC'; $criteria->limit = 1; $lastModel = Photo::model()->find($criteria); if (!empty($lastModel)) { $pos = $lastModel->pos + 1; } else { $pos = 0; } foreach ($_POST['File'] as $file) { $photo = new Photo('search'); $photo->phid = $phid; $photo->name = basename($file['name']); $photo->view = 1; $photo->pos = $pos; $photo->save(); $img = Yii::app()->image->load($_SERVER['DOCUMENT_ROOT'] . $file['name']); $pname = 'photo_' . $photo->id . '_' . basename($file['name']); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/original/' . $pname); $img->resize(600, 600); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/large/' . $pname); $img->resize(200, 200); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/medium/' . $pname); $img->resize(100, 100); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/small/' . $pname); $photo->name = $pname; $photo->save(); @unlink($_SERVER['DOCUMENT_ROOT'] . $file['name']); $pos = $pos + 1; } $this->redirect($this->createUrl('update', array('id' => $model->id, 'msg' => '[!] Фото добавлены', 'msgtype' => 'success'))); } $this->render('addphotos', array('model' => $model)); }
public function __construct() { $container_guid = getInput("container_guid"); $title = getInput("title"); $description = getInput("description"); $access_id = getInput("access_id"); for ($i = 0; $i < count($_FILES['avatar']['name']); $i++) { $photo = new Photo(); $photo->container_guid = $container_guid; $photo->owner_guid = getLoggedInUserGuid(); $photo->title = $title; $photo->description = $description; $photo->save(); $file = new File(); $file->container_guid = $photo->guid; $file->owner_guid = getLoggedInUserGuid(); $file->access_id = $photo->access_id; $file_guid = $file->save(); $file_entity = getEntity($file_guid); $target_dir = getDataPath() . "files" . "/" . $file_guid . "/"; if (!file_exists($target_dir)) { makePath($target_dir, 0777, true); } else { $files = glob($target_dir . '*', GLOB_MARK); foreach ($files as $file) { @unlink($file); } } $name = basename($_FILES['avatar']["name"][$i]); $name = preg_replace("([^\\w\\s\\d\\-_~,;:\\[\\]\\(\\).])", '', $name); $name = preg_replace("([\\.]{2,})", '', $name); $target_file = $target_dir . $name; $file_entity->path = $target_file; $file_entity->extension = pathinfo($target_file, PATHINFO_EXTENSION); $file_entity->save(); $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION); if (!empty($allowed_extensions)) { if (!in_array(strtolower($imageFileType), $allowed_extensions)) { $file_entity->delete(); new SystemMessage("Allowed file types: " . implode(" ", $allowed_extensions)); forward(); } } $error = move_uploaded_file($_FILES['avatar']["tmp_name"][$i], $target_file); $finfo = \finfo_open(FILEINFO_MIME_TYPE); $mime = \finfo_file($finfo, $target_file); \finfo_close($finfo); if ($mime == "image/jpeg" || $mime == "image/jpg" || $mime == "image/gif" || $mime == "image/png") { Image::fixImageRotation($target_file); } $file_entity->file_location = $target_file; $file_entity->mime_type = $mime; $file_entity->filename = $name; $file_entity->save(); $filename = $name; $file = getEntity($file_guid); $file->filename = $filename; $file->save(); $photo->icon = $file->guid; $photo->save(); Image::createThumbnail($file->guid, TINY); Image::createThumbnail($file->guid, SMALL); Image::createThumbnail($file->guid, MEDIUM); Image::createThumbnail($file->guid, LARGE); Image::createThumbnail($file->guid, EXTRALARGE); Image::createThumbnail($file->guid, HUGE); } new SystemMessage("Your Photo has been Uploaded"); $album_guid = $container_guid; $album = getEntity($album_guid); if (!$album->title != "Profile Avatars" && $album->title != "General") { new Activity(getLoggedInUserGuid(), "activity:add:photo", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $album->getURL(), $album->title, "<a href='" . $album->getURL() . "'>" . $photo->icon(MEDIUM, "img-responsive") . "</a>")); } forward($album->getURL()); }