/** * Norwegian map with municipalities where Alternativet is represented highlighted */ public function membersMapNorway() { $data = ""; if (!Storage::exists('members-norway-map.svg') || Storage::lastModified('members-norway-map.svg') <= time() - 60 * 60 * 24) { $svg = simplexml_load_file(base_path() . '/resources/svg/Norway_municipalities_2012_blank.svg'); // Determine which municipalities there are members in $result = DB::select(DB::raw("\n select postal_areas.municipality_code, count(*) as count\n from users\n left join postal_areas\n on (users.postal_code = postal_areas.postal_code)\n group by municipality_code")); $municipalities = []; foreach ($result as $row) { if ($row->municipality_code) { $municipalities[] = $row->municipality_code; } } foreach ($svg->g as $county) { foreach ($county->path as $path) { if (in_array($path['id'], $municipalities)) { // There are members in this municipality $path['style'] = 'fill:#0f0;fill-opacity:1;stroke:none'; } else { $path['style'] = 'fill:#777;fill-opacity:1;stroke:none'; } } } $data = $svg->asXML(); Storage::put('members-norway-map.svg', $data); } if (empty($data)) { $data = Storage::get('members-norway-map.svg'); } return response($data)->header('Content-Type', 'image/svg+xml'); }
public function putContent(Request $request) { $contents = $request->all(); $file = Storage::put('filter.txt', $contents['keywords']); flash()->success('修改成功'); return redirect()->back(); }
/** * Execute the console command. * * @return mixed */ public function handle() { //Get all reports where type = cucm_daily $reports = Report::where('type', 'cucm_daily')->get(); //Get all configured CUCM clusters $clusters = $this->cluster->all(); //Set timestamp for file names $timeStamp = Carbon::now('America/New_York')->toDateTimeString(); //Create array to track attachments $attachments = []; //Loop reports foreach ($reports as $index => $report) { $attachments[$index] = $report->path . $report->name . '-' . $timeStamp . '.csv'; //Persist report to disk Storage::put($attachments[$index], $report->csv_headers); //Loop each cluster and run the reports foreach ($clusters as $cluster) { $this->dispatch(new $report->job($cluster, $attachments[$index])); } } //Reports are done running, let's email to results $beautymail = app()->make(\Snowfire\Beautymail\Beautymail::class); $beautymail->send('emails.cucmDailyReporting', [], function ($message) use($attachments) { //TODO: Create system for users to manage report subscriptions. $message->to(['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'])->subject('CUCM Daily Report'); //Add all reports to email foreach ($attachments as $report) { $message->attach(storage_path($report)); } }); }
public function uploadPhoto($userId, $filePath, $newImage = false) { $tmpFilePath = storage_path('app') . '/' . $userId . '.png'; $tmpFilePathThumb = storage_path('app') . '/' . $userId . '-thumb.png'; try { $this->correctImageRotation($filePath); } catch (\Exception $e) { \Log::error($e); //Continue on - this isnt that important } //Generate the thumbnail and larger image Image::make($filePath)->fit(500)->save($tmpFilePath); Image::make($filePath)->fit(200)->save($tmpFilePathThumb); if ($newImage) { $newFilename = \App::environment() . '/user-photo/' . md5($userId) . '-new.png'; $newThumbFilename = \App::environment() . '/user-photo/' . md5($userId) . '-thumb-new.png'; } else { $newFilename = \App::environment() . '/user-photo/' . md5($userId) . '.png'; $newThumbFilename = \App::environment() . '/user-photo/' . md5($userId) . '-thumb.png'; } Storage::put($newFilename, file_get_contents($tmpFilePath), 'public'); Storage::put($newThumbFilename, file_get_contents($tmpFilePathThumb), 'public'); \File::delete($tmpFilePath); \File::delete($tmpFilePathThumb); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $person = new User(); $person->first_name = $request->input('first-name'); $person->last_name = $request->input('last-name'); $person->email = $request->input('work-email'); $person->personal_email = $request->input('personal-email'); $person->password = Hash::make(uniqid()); $person->address1 = $request->input('address-one'); $person->address2 = $request->input('address-two'); $person->zip = $request->input('postcode'); $person->city = $request->input('city'); $person->state = $request->input('state'); $person->country = $request->input('country'); $person->dob = Carbon::createFromFormat('d/m/Y', $request->input('dob'))->toDateString(); $person->work_telephone = $request->input('work-telephone'); $person->personal_telephone = $request->input('personal-telephone'); $person->gender = $request->input('gender'); $person->save(); // Placeholder face until one is submitted $path = 'people/' . $person->id . '/face.jpg'; \Illuminate\Support\Facades\Storage::put($path, file_get_contents('http://api.adorable.io/avatar/400/' . md5($person->id . $person->email . Carbon::now()->getTimestamp()) . '')); $person->save(); // Default job position $person->jobPositions()->attach(1, ['primary' => true]); // Default role $person->roles()->attach(1, ['primary' => true]); return redirect()->intended('/people/'); }
public function upload() { $path = $this->folder . '/' . $this->newFileName; $content = file_get_contents($this->file->getRealPath()); Storage::put($path, $content); return 'uploads/' . $path; }
/** * Store a newly created resource in storage. * * @return Response * @throws ImageFailedException * @throws \BB\Exceptions\FormValidationException */ public function store() { $data = \Request::only(['user_id', 'category', 'description', 'amount', 'expense_date', 'file']); $this->expenseValidator->validate($data); if (\Input::file('file')) { try { $filePath = \Input::file('file')->getRealPath(); $ext = \Input::file('file')->guessClientExtension(); $mimeType = \Input::file('file')->getMimeType(); $newFilename = \App::environment() . '/expenses/' . str_random() . '.' . $ext; Storage::put($newFilename, file_get_contents($filePath), 'public'); $data['file'] = $newFilename; } catch (\Exception $e) { \Log::error($e); throw new ImageFailedException($e->getMessage()); } } //Reformat from d/m/y to YYYY-MM-DD $data['expense_date'] = Carbon::createFromFormat('j/n/y', $data['expense_date']); if ($data['user_id'] != \Auth::user()->id) { throw new \BB\Exceptions\FormValidationException('You can only submit expenses for yourself', new \Illuminate\Support\MessageBag(['general' => 'You can only submit expenses for yourself'])); } $expense = $this->expenseRepository->create($data); event(new NewExpenseSubmitted($expense)); return \Response::json($expense, 201); }
protected function downloadFileInWindowsNT(TFFile $file) { $client = new Client(); try { $response = $client->get($file->source, ['verify' => false]); } catch (\Exception $e) { $error = 'TFDownloader: Downloading file failed, url is %s, msg is %s.'; $error = sprintf($error, $file->source, $e->getMessage()); Log::error($error); $file->state = 'error'; $file->error = $error; $file->save(); return; } if ($response->getStatusCode() == 200) { $location = 'file/' . $file->name; Storage::put($location, $response->getBody()); $file->state = 'downloaded'; $file->location = $location; $file->save(); return; } else { $error = 'TFDownloader: Bad HTTP response code in downloading videos, url is %s, status code is %d.'; $error = sprintf($error, $file->source, $response->getStatusCode()); Log::error($error); $file->state = 'error'; $file->error = $error; $file->save(); return; } }
/** * Save new email * * @param Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function updateEmail(Request $request) { $this->validate($request, ['email' => 'required|email']); $email = $request->get("email"); Storage::put('admin.txt', $email); return redirect("/"); }
/** * @param array $data * @return array */ public function create(array $data) { $return = parent::create($data); if (!isset($return['error'])) { Storage::put($return->id . '.' . $return->extension, File::get($data['file'])); } return $return; }
/** * Execute the command. * */ public function handle() { $newFile = File::create(['name' => 'verification_picture_' . $this->owner->user->username, 'extension' => 'jpg', 'stored_name' => str_random(64) . '.jpg', 'path' => 'verification_pictures']); $newFile->owner()->associate($this->owner); $newFile->save(); Storage::put($newFile->path . '/' . $newFile->stored_name, base64_decode(str_replace(' ', '+', $this->picture))); return $newFile; }
public function create(UploadedFile $file, User $user) { $filename = sha1(rand(11111, 99999)); $extension = $file->getClientOriginalExtension(); Storage::put('images/' . $filename . '.' . $extension, file_get_contents($file->getRealPath())); $image = new Image(['user_id' => $user->id, 'filename' => $file->getClientOriginalName(), 'path' => $filename . '.' . $extension, 'mime_type' => $file->getMimeType(), 'location' => 'local', 'status' => Image::STATUS_PENDING]); $image->save(); return $image; }
public function createFile(array $data) { $file = parent::create($data); if ($file) { if (Storage::put($data['name'] . '.' . $data['extension'], File::get($data['file']))) { return $file; } } }
public function postFile(Request $request) { $this->validate($request, ['file1' => 'required']); if ($request->ajax()) { } else { Storage::put(time() . '.jpg', file_get_contents($request->file('file1'))); } Session::flash('success', ['Task was successful!']); return redirect()->action('SampleController@getFile'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function putUpdate(Request $request) { $settings_array = $request->except('_token', '_method'); if (!in_array('enable_recaptcha', $settings_array)) { $settings_array = $settings_array + ['enable_recaptcha' => 0]; } $settings = json_encode($settings_array); Storage::put('settings.json', $settings); Cache::forever('settings', $settings_array); return redirect()->back()->withSuccess('updated'); }
public function handle() { $this->info("Fetching server data from http://203.104.209.7/gadget/js/kcs_const.js ..."); preg_match_all("/ConstServerInfo\\.World_.*\"http:\\/\\/(.*)\\/\";/", file_get_contents("http://203.104.209.7/gadget/js/kcs_const.js"), $raw); foreach ($raw[1] as $key => $value) { $ipList[$key]["id"] = $key + 1; $ipList[$key]["ip"] = $value; } Storage::put("api_servers.json", json_encode($ipList)); $this->info(count($ipList) . " server info successfully fetched."); }
public function resize($file, $newName, $width) { $image = Image::make($file)->resize($width, null, function ($constraint) { $constraint->upsize(); $constraint->aspectRatio(); }); $data = $image->encode(pathinfo($newName, PATHINFO_EXTENSION)); $saved = Storage::put(config('images.path') . $newName, $data->getEncoded()); if ($saved === false) { throw new ImageNotWritableException('Can\'t write image data to path ({$path})'); } }
/** * @param Boek[] $boek * @throws Exception */ public function store($boeken) { if (!is_array($boeken)) { throw new Exception('Wrong format'); } $store = []; foreach ($boeken as $boek) { if ($boek instanceof Boek) { $store[] = ['id' => $boek->getId(), 'isbn' => $boek->getIsbn(), 'titel' => $boek->getTitel(), 'gewicht' => $boek->getGewicht(), 'introductie' => $boek->getIntroductie()]; } } Storage::put($this->database, json_encode($store)); }
public function run() { $files = Storage::allFiles(); foreach ($files as $file) { Storage::disk('local')->delete($file); } $products = Product::all(); foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235/')); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->faker->name]); } }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ public function create(array $data) { $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'database' => $data['name'] . '.sqlite', 'password' => bcrypt($data['password'])]); // Create the new user sqlite database Storage::put($user->database, ''); // Close any connection made with tenantdb DB::disconnect('tenantdb'); // Set the tenant connection to the users own database Config::set('database.connections.tenantdb.database', storage_path() . '/' . $user->database); // Run migrations for the new db Artisan::call('migrate', ['--database' => 'tenantdb', '--path' => 'database/migrations/tenant']); return $user; }
public static function getUrl(ResponseType $responseType, $request) { if ($responseType->name == 'link' || $responseType->name == 'video') { return $request->input('url'); } else { $file = $request->file('file'); if ($file) { $pathFile = 'responses/' . Auth::user()->id . '_' . uniqid() . '.jpg'; Storage::put($pathFile, file_get_contents($file->getRealPath())); return '/' . $pathFile; } } return ''; }
/** * @param Organization $organization * @param OrganizationData $organizationData * @param Settings $settings * @param $orgElem * @return mixed */ public function generateXml(Organization $organization, OrganizationData $organizationData, Settings $settings, $orgElem) { $xml = $this->getXml($organization, $organizationData, $settings, $orgElem); $filename = $settings['registry_info'][0]['publisher_id'] . '-org.xml'; $result = Storage::put(sprintf('%s%s', config('filesystems.xml'), $filename), $xml->saveXML()); if ($result) { $published = $this->organizationPublished->firstOrNew(['filename' => $filename, 'organization_id' => $organization->id]); $published->touch(); $published->filename = $filename; $published->organization_id = $organization->id; $published->save(); } return $settings['registry_info'][0]['publish_files'] == 'yes' ? $this->organizationManager->publishToRegistry($organization, $settings, $filename) : true; }
/** * Store collection * @param Collection $collection */ private function storeCollection(Collection $collection) { Cache::flush($this->getCacheQuequeMask()); if (config('lauser.save_type') == 'file') { $path = $this->getLaUserFilePathById($this->id); Storage::put($path, $collection->toJson()); } else { $isExists = DB::table(config('lauser.save_table'))->where('user_id', $this->id)->count(); if ($isExists > 0) { DB::table(config('lauser.save_table'))->where('user_id', $this->id)->update(['json' => $collection->toJson()]); } else { DB::table(config('lauser.save_table'))->insert(['user_id' => $this->id, 'json' => $collection->toJson()]); } } }
/** * @param File $file * @param $data * * @return File|false */ public function update(File $file, $data) { if (!is_null($file->path)) { $currentFilePath = $file->path; } $file->fill(array_merge($data, [File::PATH => FilesStorage::getFilesDirectory() . $data[File::CLIENT_ORIGINAL_NAME]])); $fileIsStored = Storage::put($file->path, file_get_contents($data[File::TEMPORARY_PATH])); if (!$fileIsStored || !$file->save()) { return false; } if (isset($currentFilePath)) { Storage::delete($currentFilePath); } return $file; }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create('en_GB'); $user = \App\Models\User::create(['email' => '*****@*****.**', 'personal_email' => $faker->safeEmail, 'password' => \Illuminate\Support\Facades\Hash::make('password'), 'first_name' => $faker->firstNameFemale, 'last_name' => $faker->lastName, 'dob' => $faker->dateTimeBetween('-30 years', 'now'), 'gender' => 'f', 'address1' => $faker->streetAddress, 'city' => $faker->city, 'state' => 'Any State', 'zip' => $faker->postcode, 'country' => 'United Kingdom', 'personal_telephone' => $faker->mobileNumber, 'work_telephone' => $faker->phoneNumber]); if ($user) { // Generate and save image $path = 'people/' . $user->id . '/face.jpg'; \Illuminate\Support\Facades\Storage::put($path, file_get_contents('http://api.adorable.io/avatar/400/' . md5($user->id . $user->email) . '')); $user->image_path = $path; $user->save(); $user->roles()->attach(\App\Models\Role::where('name', '=', 'admin')->first(), ['primary' => true]); $user->jobPositions()->attach(\App\Models\JobPosition::where('name', '=', 'Boss')->first(), ['primary' => true]); } $this->command->info('Administration user created. Username: administrator@progress.local, password: password.'); }
/** * Create a webshot by link * * @param Request $request * @return \Symfony\Component\HttpFoundation\Response * @throws \Exception */ public function store(Request $request) { $this->validate($request, ['url' => 'required|url', 'extension' => 'in:jpg,png,pdf', 'width' => 'integer', 'height' => 'integer', 'full_page' => 'boolean', 'filename' => 'alpha_dash', 'timeout' => 'integer', 'path' => 'string']); $filename = $request->input('filename', sha1($request->input('url'))); $fullPath = trim(str_replace(' ', '-', $request->input('path', date('Y/m/d'))), '/') . '/' . $filename . '.' . $request->input('extension', 'jpg'); $tmpPath = storage_path('app'); $webshot = new Webshot(env('PHANTOM_JS_BIN')); try { $tmpFile = $webshot->setUrl($request->input('url'))->setWidth($request->input('width', 1200))->setHeight($request->input('height', 800))->setFullPage($request->input('full_page', false))->setTimeout($request->input('timeout', 30))->{'saveTo' . ucfirst($request->input('extension', 'jpg'))}($filename, $tmpPath); // Put file to it's destination Storage::put($fullPath, file_get_contents($tmpFile)); unlink($tmpFile); return response()->json(['path' => $fullPath, 'url' => app('filesystemPublicUrl')->publicUrl(null, $fullPath)]); } catch (TimeoutException $e) { return response()->json(['message' => 'Link timeout.'], 500); } }
public function setup() { $user = Auth::user(); $email = $user->email; $images = DB::table('images')->where('email', '=', $email)->orderBy('id', 'asc')->get(); //var_dump($images); foreach ($images as $image) { $path = $email . "/" . $image->name; if (Storage::exists($path)) { Storage::delete($path); } $file = Storage::put($path, $image->image); var_dump($image->image); echo "{$path} created!"; } return redirect('home'); }
public function postUpload(Request $request) { /** @var Ulibier $user */ $user = JWTAuth::parseToken()->authenticate(); $image = $request->file('image'); $photo_uptime = time(); $hash = uniqid($photo_uptime, true); $imageFilename = $hash . '.' . $image->getClientOriginalExtension(); Storage::put('/imgtemp/' . $imageFilename, file_get_contents($image), 'public'); $photo = Photo::create(); $photo->photo_uptime = $photo_uptime; $photo->photo_hash = $hash; $photo->photo_extensions = $image->getClientOriginalExtension(); $photo->des_id = $request->input('des_id'); $photo->save(); $user->photos()->save($photo); return $photo; }
public function index() { if (Storage::disk('local')->has('data.txt')) { if (!Storage::disk('local')->has('data_temp.txt')) { Storage::copy('data.txt', 'data_temp.txt'); } $file = Storage::disk('local')->get('data.txt'); if (strlen($file) == 0) { $content_temp = Storage::disk('local')->get('data_temp.txt'); Storage::put('data.txt', $content_temp); } $file = Storage::disk('local')->get('data.txt'); $small = substr($file, 0, strpos($file, "\n")); $file = substr($file, strpos($file, "\n") + 1); Storage::put('data.txt', $file); return Response::json(array('line' => $small)); } }
/** * Upload file to filesystem. * * @param UploadedFile $file * * @return array */ protected function uploadFile(UploadedFile $file) { // Randomly generate filename if one does not exist. if (!$this->filename) { $this->filename = Str::random() . time(); } // Setup full file names with extensions. $full_filename = "{$this->filename}.{$file->getClientOriginalExtension()}"; // If directory is set, prepend it to the $full_filename string. if (!empty($this->directory)) { $full_filename = "{$this->directory}/{$full_filename}"; } // Put the file onto the filesystem. $stream = file_get_contents($file->getRealPath()); $this->filesystem->put($full_filename, $stream); // Get the URI paths of the files. $path = $this->getUploadUri($full_filename); return $path; }