public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Photo::create([]); } }
public function run() { $faker = Faker::create(); foreach (range(1, 500) as $index) { Photo::create(array('title' => $faker->sentence($nbwords = 5), 'image' => $faker->imageUrl($width = 640, $height = 480), 'gallery_id' => $faker->numberBetween(1, 50))); } }
public function postNewAdmin() { //verify the user input and create account $validator = Validator::make(Input::all(), array('Identity_No' => 'required', 'Email' => 'required|email', 'Phone_Number' => 'required', 'First_Name' => 'required', 'Last_Name' => 'required', 'Photo_1' => 'image|required', 'Photo_2' => 'image|required', 'Photo_3' => 'image|required')); if ($validator->fails()) { return Redirect::route('super-admin-new-admin-get')->withErrors($validator)->withInput()->with('globalerror', 'Sorry!! The Data was not Saved, please retry'); } else { $identitynumber = Input::get('Identity_No'); $email = Input::get('Email'); $phonenumber = Input::get('Phone Numer'); $firstname = Input::get('First_Name'); $lastname = Input::get('Last_Name'); $photo_1 = Input::file('Photo_1'); $photo_2 = Input::file('Photo_2'); $photo_3 = Input::file('Photo_3'); //register the new user $newuser = User::create(array('Identity_No' => $identitynumber, 'First_Name' => $firstname, 'Last_Name' => $lastname, 'Password' => Hash::make($identitynumber), 'Active' => TRUE)); //register the new user contact $newcontact = Contact::create(array('Email' => $email, 'Phone_Number' => $phonenumber)); //Save the three Photos $photo1 = $this->postPhoto($photo_1); $photo2 = $this->postPhoto($photo_2); $photo3 = $this->postPhoto($photo_3); $newphotos = Photo::create(array('photo_1' => $photo1, 'photo_2' => $photo2, 'photo_3' => $photo3)); //save the details to the students table $newadmin = Admin::create(array('Users_Id' => $newuser->id, 'Contacts_Id' => $newcontact->id, 'Photos_Id' => $newphotos->id)); if ($newuser && $newcontact && $newphotos && $newadmin) { return Redirect::route('super-admin-new-admin-get')->with('globalsuccess', 'New Admin Details Have been Added'); } } }
public function run() { $faker = Faker::create(); foreach (range(1, 1) as $index) { Photo::create(['user_id' => 1, 'path' => 'img/image1.jpg', 'caption' => 'caption 1.']); Photo::create(['user_id' => 2, 'path' => 'img/image2.jpg', 'caption' => 'caption 2.']); } }
public function run() { $faker = Faker::create(); $usersId = DB::table('users')->lists('id'); $albumsId = DB::table('albums')->lists('id'); $imgNames = ['test.png', 'sample.jpg', 'default.jpg', 'preview.png']; for ($i = 0; $i < 100; $i++) { Photo::create(['title' => $faker->word(), 'img_name' => $imgNames[rand(0, sizeof($imgNames) - 1)], 'author_id' => $usersId[rand(0, sizeof($usersId) - 1)], 'album_id' => $albumsId[rand(0, sizeof($albumsId) - 1)]]); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::all(); if ($this->photo->isValid($input)) { $mime = $input['file']->getMimeType(); $fileName = time() . "." . strtolower($input['file']->getClientOriginalExtension()); $image = Image::make($input['file']->getRealPath()); $this->upload_s3($image, $fileName, $mime, "high"); $image->resize(400, 300); $this->upload_s3($image, $fileName, $mime, "low"); Photo::create(['title' => Input::get('title'), 'file' => $fileName]); Session::flash('exito', 'La foto se ha subido con éxito'); return Redirect::route('photo.index'); } else { Session::flash('error', 'Se ha producido un error al subir la imagen'); return Redirect::back()->withInput()->withErrors($this->photo->messages); } }
public function testMorph() { $user = User::create(array('name' => 'John Doe')); $client = Client::create(array('name' => 'Jane Doe')); $photo = Photo::create(array('url' => 'http://graph.facebook.com/john.doe/picture')); $photo = $user->photos()->save($photo); $this->assertEquals(1, $user->photos->count()); $this->assertEquals($photo->id, $user->photos->first()->id); $user = User::find($user->_id); $this->assertEquals(1, $user->photos->count()); $this->assertEquals($photo->id, $user->photos->first()->id); $photo = Photo::create(array('url' => 'http://graph.facebook.com/jane.doe/picture')); $client->photo()->save($photo); $this->assertNotNull($client->photo); $this->assertEquals($photo->id, $client->photo->id); $client = Client::find($client->_id); $this->assertNotNull($client->photo); $this->assertEquals($photo->id, $client->photo->id); $photo = Photo::first(); $this->assertEquals($photo->imageable->name, $user->name); $user = User::with('photos')->find($user->_id); $relations = $user->getRelations(); $this->assertTrue(array_key_exists('photos', $relations)); $this->assertEquals(1, $relations['photos']->count()); $photos = Photo::with('imageable')->get(); $relations = $photos[0]->getRelations(); $this->assertTrue(array_key_exists('imageable', $relations)); $this->assertInstanceOf('User', $relations['imageable']); $relations = $photos[1]->getRelations(); $this->assertTrue(array_key_exists('imageable', $relations)); $this->assertInstanceOf('Client', $relations['imageable']); }
public function postEditEvent() { //verify the user input and create account $validator = Validator::make(Input::all(), array('Id' => 'required', 'Title' => 'required|max:200', 'Description' => 'required', 'Date' => 'required', 'First_Name' => 'required|max:120', 'Last_Name' => 'required|max:120', 'Pic' => 'image|max:3000', 'Room' => 'required')); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput()->with('global', 'Sorry!! Your Event was not edited, please retry.'); } else { $id = Input::get('Id'); $title = Input::get('Title'); $description = Input::get('Description'); $firstname = Input::get('First_Name'); $lastname = Input::get('Last_Name'); $date = Input::get('Date'); $file = Input::file('Pic'); $roomid = Input::get('Room'); if (Auth::user()) { $organiserid = Auth::user()->id; } else { $organiserid = 0; } $eventedit = Lecture::where('id', '=', $id); $pic_id = 0; //post photo if ($file != null) { //photos validation $destinationPath = 'pics'; $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 $upload_success = $file->move($destinationPath, $hashname); //Set the photo path name to hashname $pic = Photo::create(array('path' => 'pics/' . $hashname)); if ($pic) { $pic_id = $pic->id; } } if ($eventedit->count()) { $eventedit = $eventedit->first(); //edit the details $eventedit->organiser_id = $organiserid; $eventedit->room_id = $roomid; $eventedit->pic_id = $pic_id; $eventedit->title = $title; $eventedit->overview = $description; $eventedit->date = $date; $presenter_edit = Presenter::where('id', '=', $eventedit->presenter_id); if ($presenter_edit->count()) { $presenter_edit = $presenter_edit->first(); } $presenter_edit->firstname = $firstname; $presenter_edit->lastname = $lastname; $saved1 = $presenter_edit->save(); $saved2 = $eventedit->save(); return View::make('organiser.success'); } } return Redirect::back()->withInput()->with('global', 'Sorry!! Your Event was not edited, please retry.'); }
public function postSingleupload($param_name = 'file', $return = 'ajax') { ## Upload gallery image $result = $this->uploadImage($param_name); ## Check response if ($result['result'] == 'error') { if (Request::ajax()) { return Response::json($result, 400); } else { return false; } } ## Make photo object $photo = Photo::create(array('name' => $result['filename'], 'gallery_id' => 0, 'title' => '')); ## All OK, return result $result['result'] = 'success'; $result['image_id'] = $photo->id; $result['gallery_id'] = -1; $result['thumb'] = $photo->thumb(); $result['full'] = $photo->full(); if (Request::ajax() && $return == 'ajax') { return Response::json($result, 200); } else { return $photo; } }
/** * undocumented function * * @return void * @author **/ public static function add(array $input) { return Photo::create($input); }
public function create($data, $filename, $visibility) { if ($data == '') { // attempt to overcome PHP bug that causes // the HTTP POST value to be empty // it seems that PHP is trying to urldecode the // raw HTTP POST string, but for big enough values // this causes a memory overflow and the data // item remains unset // Here we process the php://input stream directly. $vars = explode('&', file_get_contents('php://input')); foreach ($vars as $var) { $vardata = explode('=', $var); $key = $vardata[0]; $value = $vardata[1]; if ($key == 'data') { $data = urldecode($value); break; } } } if (!isset($_SESSION['user'])) { throw new Exception('Not authorized.'); } if ($data == '') { echo "Data provided is empty. Dumping {$_POST} variable.\n"; var_dump($_POST); throw new Exception('Data provided is empty.'); } $filename = strtolower($filename); $extension = substr($filename, strrpos($filename, '.') + 1); switch ($extension) { case 'jpg': case 'gif': case 'png': break; default: throw new Exception('Unrecognized image type. Expected "jpg", "gif", or "png", but got "' . $extension . '".'); } switch ($visibility) { case 'public': case 'private': break; default: throw new Exception('Invalid visibility; expected "public" or "private", but got "' . $visibility . '"'); } $data = base64_decode($data); if ($data === false) { throw new Exception('Invalid data supplied: data is not base64-encoded.'); } $im = @imagecreatefromstring($data); if ($im !== false) { $width = imagesx($im); $height = imagesy($im); } else { echo 'Warning: We believe this is not a valid image file, but we\'re uploading it anyway.'; $width = 0; $height = 0; } $result = Photo::create($filename, $extension, strlen($data), $_SESSION['user']['id'], $width, $height); $id = $result['id']; $filename = $result['filename']; $uploadfile = 'uploads/' . $filename; if (file_exists($uploadfile)) { throw new Exception('File already exists.'); } file_put_contents($uploadfile, $data); $taken = Photo::timeFromFile($uploadfile); Photo::update($id, $taken); echo 'File uploaded successfully.'; Post::create($filename, $_SESSION['user']['id'], 'photo', $visibility, $taken); }
<div id="page-wrapper"> <div class="container-fluid"> <!-- Page Heading --> <div class="row"> <div class="col-lg-12"> <h1 class="page-header"> Blank Page <small>Subheading</small> </h1> <?php $photo = new Photo(); $photo->photo_title = "fsdfsd"; $photo->create(); ?> <ol class="breadcrumb"> <li> <i class="fa fa-dashboard"></i> <a href="index.html">Dashboard</a> </li> <li class="active"> <i class="fa fa-file"></i> Blank Page </li> </ol> </div> </div> <!-- /.row --> </div> <!-- /.container-fluid --> </div>
public static function upload($url, $gallery = NULL, $title = '') { $img_data = @file_get_contents($url); if (!$img_data) { return false; } $tmp_path = storage_path(md5($url)); try { file_put_contents($tmp_path, $img_data); } catch (Exception $e) { echo 'Error #' . $e->getCode() . ':' . $e->getMessage() . "<br/>\n"; echo 'In file: ' . $e->getFile() . ' (' . $e->getLine() . ')'; die; } $file = new \Symfony\Component\HttpFoundation\File\UploadedFile($tmp_path, basename($url)); ## Check upload & thumb dir $uploadPath = Config::get('site.galleries_photo_dir'); $thumbsPath = Config::get('site.galleries_thumb_dir'); if (!File::exists($uploadPath)) { File::makeDirectory($uploadPath, 0777, TRUE); } if (!File::exists($thumbsPath)) { File::makeDirectory($thumbsPath, 0777, TRUE); } ## Generate filename $fileName = time() . "_" . rand(1000, 1999) . '.' . $file->getClientOriginalExtension(); #echo $fileName; ## Get images resize parameters from config $thumb_size = Config::get('site.galleries_thumb_size'); $photo_size = Config::get('site.galleries_photo_size'); ## Get image width & height $image = ImageManipulation::make($file->getRealPath()); $w = $image->width(); $h = $image->height(); if ($thumb_size > 0) { ## Normal resize $thumb_resize_w = $thumb_size; $thumb_resize_h = $thumb_size; } else { ## Resize "by the smaller side" $thumb_size = abs($thumb_size); ## Resize thumb & full-size images "by the smaller side". ## Declared size will always be a minimum. $thumb_resize_w = $w > $h ? null : $thumb_size; $thumb_resize_h = $w > $h ? $thumb_size : null; } ## Resize thumb image $thumb_upload_success = ImageManipulation::make($file->getRealPath())->resize($thumb_resize_w, $thumb_resize_h, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->save($thumbsPath . '/' . $fileName); if ($photo_size > 0) { ## Normal resize $image_resize_w = $photo_size; $image_resize_h = $photo_size; } else { ## Resize "by the smaller side" $photo_size = abs($photo_size); ## Resize full-size images "by the smaller side". ## Declared size will always be a minimum. $image_resize_w = $w > $h ? null : $photo_size; $image_resize_h = $w > $h ? $photo_size : null; } ## Resize full-size image $image_upload_success = ImageManipulation::make($file->getRealPath())->resize($image_resize_w, $image_resize_h, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->save($uploadPath . '/' . $fileName); ## Delete original file unlink($file->getRealPath()); ## Gallery - none, existed, new $gallery_id = 0; if (is_int($gallery) && $gallery > 0) { $gallery_id = $gallery; } elseif (is_string($gallery)) { $gal = Gallery::create(['name' => $gallery]); $gallery_id = $gal->id; } ## Create MySQL record $photo = Photo::create(array('name' => $fileName, 'gallery_id' => $gallery_id, 'title' => $title)); return $photo; }
public function postNewVoter() { //verify the user input and create account $validator = Validator::make(Input::all(), array('Identity_No' => 'required', 'Email' => 'required|email', 'Phone_Number' => 'required', 'First_Name' => 'required', 'Last_Name' => 'required', 'Faculty' => 'required', 'Residence' => 'required', 'Photo_1' => 'image|required|mimes:jpeg,bmp,png', 'Photo_2' => 'image|required|mimes:jpeg,bmp,png', 'Photo_3' => 'image|required|mimes:jpeg,bmp,png')); if ($validator->fails()) { return Redirect::route('admin-new-voter-get')->withErrors($validator)->withInput()->with('globalerror', 'Sorry!! The Data was not Saved, please retry'); } else { $identitynumber = Input::get('Identity_No'); $email = Input::get('Email'); $phonenumber = Input::get('Phone Numer'); $firstname = Input::get('First_Name'); $lastname = Input::get('Last_Name'); $faculty_id = Input::get('Faculty'); $residence_id = Input::get('Residence'); $photo_1 = Input::file('Photo_1'); $photo_2 = Input::file('Photo_2'); $photo_3 = Input::file('Photo_3'); //register the new user $newuser = User::create(array('Identity_No' => $identitynumber, 'First_Name' => $firstname, 'Last_Name' => $lastname, 'Password' => Hash::make($identitynumber), 'Active' => TRUE, 'User_Level' => 'voter')); //register the new user contact $newcontact = Contact::create(array('Email' => $email, 'Phone_Number' => $phonenumber)); //Save the three Photos $photo1 = $this->postPhoto($photo_1, $newuser->id); $photo2 = $this->postPhoto($photo_2, $newuser->id); $photo3 = $this->postPhoto($photo_3, $newuser->id); $newphotos = Photo::create(array('photo_1' => $photo1, 'photo_2' => $photo2, 'photo_3' => $photo3)); //save the details to the students table $newstudent = Student::create(array('Users_Id' => $newuser->id, 'Faculties_Id' => $faculty_id, 'Residences_Id' => $residence_id, 'Contacts_Id' => $newcontact->id, 'Photos_Id' => $newphotos->id, 'Active' => TRUE)); if ($newuser && $newcontact && $newphotos && $newstudent) { //update the eigenfaces model with to include the new facedata putenv("PYTHONPATH=/usr/lib/python2.7"); putenv("LD_LIBRARY_PATH=/usr/local/lib"); //call python class to create the eigenfaces models from the existing photos exec("python /opt/lampp/htdocs/jkuatvs/eigensave.py /opt/lampp/htdocs/jkuatvs/photos"); return Redirect::route('admin-new-voter-get')->with('globalsuccess', 'New Voter Details Have been Added'); } } }
public function addPhoto($fname, $data) { $photo_path = $this->getPhotoPath(); $photo = new Photo(); $new_name = mktime() . rand(0, 1000); //rename(PHOTOS_TMP_PATH.$fname,$photo_path.$new_name); rename(PHOTOS_TMP_PATH . $fname . '_prev', $photo_path . $new_name . '_prev'); $img = imagecreatefromjpeg(PHOTOS_TMP_PATH . $fname); //$im=Photo::createWatermark($img,WATERMARK,"arial.ttf",255,255,255,100); imagejpeg($img, $photo_path . $new_name); $tag = clearTextData($data['photo_type_' . $fname]); $title = clearTextData($data['photo_title_' . $fname]); $description = clearTextData($data['photo_desc_' . $fname]); $values = array('kind_id' => $this->_kind, 'object_id' => $this->id, 'tag' => $tag, 'name' => $new_name, 'title' => $title, 'description' => $description, 'created_on' => date("Y-m-d H:i:s"), 'status' => 0); $photo->create($values); }
public static function savePhoto($id, $fname, $data) { $called_class = get_called_class(); $photo_path = $called_class::getPhotoPathStatic($id); $photo = new Photo(); $new_name = mktime() . rand(0, 1000); //rename(PHOTOS_TMP_PATH.$fname,$photo_path.$new_name); rename(PHOTOS_TMP_PATH . $fname . '_prev', $photo_path . $new_name . '_prev'); $img = imagecreatefromjpeg(PHOTOS_TMP_PATH . $fname); //$im=Photo::createWatermark($img,WATERMARK,"arial.ttf",255,255,255,100); imagejpeg($img, $photo_path . $new_name); $tag = clearTextData($data['photo_type_' . $fname]); $title = clearTextData($data['photo_title_' . $fname]); $description = clearTextData($data['photo_desc_' . $fname]); $values = array('kind_id' => constant(strtoupper($called_class)), 'object_id' => $id, 'name' => $new_name, 'title' => $title, 'description' => $description, 'created_on' => date("Y-m-d H:i:s"), 'status' => 0); $photo->create($values); }
\Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); $app->group('/news', function () use($app) { News::create($app); }); $app->group('/tags', function () use($app) { Tags::create($app); }); $app->group('/resources', function () use($app) { Resource::create($app); }); $app->group('/category', function () use($app) { Category::create($app); }); $app->group('/album', function () use($app) { Photo::create($app); }); $app->get('/ninja', function () use($app) { chdir('../ninja'); $ninja = glob('*'); $res = array(); foreach ($ninja as $n) { array_push($res, ['name' => $n, 'url' => "/ninja/{$n}/"]); } echo json_encode($res); }); $app->post('/login', function () use($app) { $data = json_decode($app->request->getBody()); $pass = $data->password; $secret = password_hash($_SERVER['ADMIN_PASS'], PASSWORD_DEFAULT); if (password_verify($pass, $secret)) {
$URL = './index.php'; break; case 'photo_add': $upload = new Upload(); $upload->SetFileName($_FILES['photo']['name']); $upload->SetTempName($_FILES['photo']['tmp_name']); $upload->SetUploadDirectory(ROOT . '/photos/' . $_POST['project_id'] . '/'); $upload->SetValidExtensions(array('gif', 'jpg', 'jpeg', 'png')); if ($upload->UploadFile()) { $p = new Photo(); $photo['project_id'] = addslashes($_POST['project_id']); $photo['name'] = $upload->GetFileName(); $photo['position'] = count($p->find_by_project_id($photo['project_id'])) + 1; $photo['created_at'] = $todayDate; $photo['updated_at'] = $todayDate; $p->create($photo); } $URL = './photos.php?id=' . $_POST['project_id']; break; case 'photo_delete': parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY)); $photo = new Photo(); $photo = $photo->find($id); $project_id = $photo->project_id; unlink(ROOT . '/photos/' . $project_id . '/' . $photo->name); $photo->delete(); $photos = new Photo(); $photos = $photos->order_by('position')->find_by_project_id($project_id); foreach ($photos as $i => $photo) { $photo->position = $i + 1; $photo->save();
public static function getUploadedImageFile($input = 'file') { if (Input::hasFile($input)) { $fileName = time() . "_" . rand(10000000, 19999999) . '.' . Input::file($input)->getClientOriginalExtension(); Input::file($input)->move(Config::get('site.galleries_photo_dir'), $fileName); $photo = Photo::create(array('name' => $fileName, 'gallery_id' => 0)); return $photo->id; } return FALSE; }