download() public static method

Create a new file download response.
public static download ( SplFileInfo | string $file, string $name = null, array $headers = [], string | null $disposition = 'attachment' ) : BinaryFileResponse
$file SplFileInfo | string
$name string
$headers array
$disposition string | null
return Symfony\Component\HttpFoundation\BinaryFileResponse
Example #1
0
 public function getDownload()
 {
     //PDF file is stored under project/public/download/info.pdf
     $file = public_path() . "/download/info.pdf";
     $headers = array('Content-Type: resume/docx');
     return Response::download($file, 'alexandra_gutierrez_resume.pdf', $headers);
 }
Example #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $filename = $this->argument('set') . "set.arff";
     $handle = fopen($filename, 'w+');
     $text = "@relation 'price'\n@attribute y {-1,1}\n@attribute x0 numeric\n@attribute x1 numeric\n@attribute x3 numeric\n@attribute x4 numeric\n@attribute x5 numeric\n@attribute x6 numeric\n@attribute x7 numeric\n@attribute x8 numeric\n@attribute x9 numeric\n@data\n\n";
     $set = \MkmScraper\Set::find($this->argument('set'));
     $array = array(array());
     foreach ($set->mythics as $card) {
         foreach ($card->graphPrices as $key => $price) {
             $row = array();
             $row[] = $price->priceClass();
             $row[] = $price->card->set->daysFromReleaseDate($price->date);
             $row[] = $price->card->set->daysFromRotationDate($price->date);
             $row[] = $price->tournamentDiffWeek();
             $row[] = $price->tournamentDiffTwoWeek();
             $row[] = $price->articlesDiffLastWeek();
             $row[] = $price->articlesDiffLastTwoWeek();
             $row[] = $price->otherCardMovementDay();
             $row[] = $price->otherCardMovementWeek();
             $row[] = $price->boostersOpen();
             $array[] = $row;
         }
     }
     foreach ($array as $row) {
         foreach ($row as $item) {
             $text .= $item . ",";
         }
         $text .= "\n";
     }
     file_put_contents($filename, $text);
     return \Response::download($this->argument('set') . 'set.arff', $this->argument('set') . 'set.arff', array('Content-Type' => 'text/aarf'));
 }
 /**
  * Store a newly created resource in storage.
  * POST /policies
  *
  * @return Response
  */
 public function store($id)
 {
     //
     $download = AdminPolicies::where('download_id', $id)->first();
     $destinationPath = storage_path('download_files/' . $download->pdffile);
     return Response::download($destinationPath);
 }
 public function getDownload()
 {
     //to prevent users from downloading posters created by other people we get the folder hash from the session.
     $hash = Session::get('hash');
     $destinationPath = 'uploads/' . $hash;
     return Response::download($destinationPath . '/poster.jpg');
 }
 public function exportCustomerData()
 {
     $customers = CustomerData::orderBy('id')->get();
     $customers = $customers->toArray();
     $filename = CustomerData::exportData($customers);
     return Response::download(public_path($filename));
 }
Example #6
0
 protected function download(Path $path)
 {
     // check basic auth headers as well, so if specified,
     // client doesn't have to go through the login and cookie dance.
     Auth::onceBasic("username");
     // check we're logged in
     if (!Auth::check()) {
         Session::flash('redirect', URL::current());
         return Redirect::route('login');
     }
     // record the download in the db
     $record = $path->loadCreateRecord($path);
     $record->downloaded_at = $record->freshTimestamp();
     $record->increment('downloads');
     $record->save();
     $isMisc = strpos($path->getRelative(), '/Misc/') === 0;
     if ($isMisc || $path->isSafeExtension()) {
         // check if the extension is safe to download
         $file = new AsciiSafeDownloadFile($path->getPathname());
         // see comments in AsciiSafeDownloadFile class
         $baseName = $path->getBasename();
         $baseName = str_replace('%', '', $baseName);
         try {
             return Response::download($file, $baseName);
         } catch (InvalidArgumentException $e) {
             App::abort(500, 'This file has a malformed filename. Please contact an admin.');
         }
     } else {
         App::abort(403, sprintf('File type "%s" not allowed', $path->getExtension()));
     }
 }
Example #7
0
 public function create($type = 'csv')
 {
     try {
         $export = static::getExportForType($type);
     } catch (Exception $e) {
         App::abort(404);
     }
     $export->user_id = Auth::user()->id;
     $export->filename = $export->generateFilename();
     $export->path = $export->folderPath();
     $export->setLogbooks(Input::get('logbooks'));
     $save = Input::has('save') ? (bool) Input::get('save') : true;
     if ($export->run($save)) {
         if ($save == false) {
             $res = Response::make($export->content);
             $res->header('Content-type', $export->getContentType());
             return $res;
         } else {
             $export->save();
             return Response::download($export->fullPath(), $export->filename, ['Content-type' => $export->getContentType()]);
         }
     } else {
         return Redirect::to(action('ExportsController@index'))->with('message', ['content' => 'Er is iets mis gegaan met exporteren.', 'class' => 'danger']);
     }
 }
Example #8
0
 public static function downloadFile($id)
 {
     $record = self::find($id);
     if (!$record) {
         return \Response::json(['success' => false, 'message' => 'No record ...']);
     }
     return \Response::download($record->file_url, basename($record->file_name), []);
 }
Example #9
0
 protected function downloadingLocalOrCloudFiles($fname)
 {
     if (!config('veer.use_cloud_files')) {
         return \Response::download(storage_path() . '/app/' . config('veer.downloads_path') . "/" . $fname);
     } else {
         return redirect(config('veer.cloudstorage_path') . '/' . config('veer.downloads_path') . '/' . $fname);
     }
 }
 /**
  * Download file
  *
  * @return Response
  */
 public function download_file($filename)
 {
     $file = public_path() . "/uploads/{$filename}";
     if (File::isFile($file)) {
         $headers = array('Content-Type: application/pdf', 'application/octet-stream', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/pdf');
         return Response::download($file, $filename, $headers);
     }
 }
 /**
  * Show artist profile picture
  *
  * @return Response
  */
 public function profilepicture($id, $type)
 {
     $pic = Picture::find($id);
     if ($pic) {
         return Response::download(storage_path() . "/pictures/" . $pic->name . "-" . $type . $pic->extension);
     } else {
         return Response::download(storage_path() . "/no-user.png");
     }
 }
 /**
  * Show hub picture
  *
  * @return Response
  */
 public function picture($id)
 {
     $pic = Picture::find($id);
     if ($pic) {
         return Response::download(storage_path() . "/pictures/" . $pic->name . ".png");
     } else {
         return App::abort(404);
     }
 }
Example #13
0
 public function getFileBinToShowById($id)
 {
     /** @var FileModel $file */
     $file = FileModel::where('id', $id)->first();
     if (!$file || !$file->baseFile) {
         throw new NotFoundException(NotFoundException::FileNotFound);
     }
     return \Response::download($file->baseFile->getLocalCachePath(), [], 'inline');
 }
 public function getfile($filename)
 {
     $myfile = storage_path() . '/uploads/traces/' . $filename;
     if (!\File::exists($myfile)) {
         echo "File not exists.";
     } else {
         return \Response::download($myfile, $filename);
     }
 }
Example #15
0
 public function do_download($file)
 {
     //return Str::random(100);
     if (Auth::check()) {
         // return Redirect::to('https://www.sugarsync.com/pf/D9604663_69636075_6847618?directDownload=true');
         $pathToFile = '/Users/myalienvirus/Sites/downloads/public/downloads/';
         return Response::download($pathToFile . 'office11.Mac.iso');
     }
     return Redirect::to('/');
 }
Example #16
0
 public function backup()
 {
     // path file
     $file = storage_path() . '/backups/' . date('dmYHis') . '.sql';
     // dump database
     $dump = new Dump();
     $dump->file($file)->dsn($this->dsn)->user($this->user)->pass($this->pass);
     new Export($dump);
     // unduh file dump
     return Response::download($file, date('dmYHis') . '.sql');
 }
 public function index()
 {
     if (\Input::get('l')) {
         LaravelLogViewer::setFile(base64_decode(\Input::get('l')));
     }
     if (\Input::get('dl')) {
         return \Response::download(storage_path() . '/logs/' . base64_decode(\Input::get('dl')));
     }
     $logs = LaravelLogViewer::all();
     return View::make('laravel-log-viewer::log', ['logs' => $logs, 'files' => LaravelLogViewer::getFiles(true), 'current_file' => LaravelLogViewer::getFileName()]);
 }
Example #18
0
 public function download($id, $token = null, $token_type = null)
 {
     $file = $this->get($id);
     if ($token_type == 'file') {
         $this->willDownloadFromFile($file, $token);
     }
     $file->downloads += 1;
     $file->save();
     $headers = $this->getHeadersForFile($file);
     return \Response::download($file->system_path, $file->filename, $headers);
 }
 /**
  *
  * @return Response::Download as txt file
  */
 public function download()
 {
     $shops = Shop::all();
     $filename = "shop.txt";
     $handle = fopen($filename, 'w+');
     foreach ($shops as $row) {
         fputcsv($handle, array($row['name'], $row['floor'], $row['lot_no']));
     }
     fclose($handle);
     $headers = array('Content-Type' => 'txt');
     return \Response::download($filename, 'shops.txt', $headers);
 }
Example #20
0
 /**
  * Backup Gists
  *
  * If the time of last backup is less than 5 minutes ago, interrupts and returns a string.
  * Otherwise returns the archived file response.
  *
  * @return string | \Symfony\Component\HttpFoundation\BinaryFileResponse
  */
 public function backup()
 {
     $user = $this->userFinder->getAuthenticatedUser();
     $userCanBackup = GistBackupHandler::checkLastBackupTime($user);
     if (!$userCanBackup) {
         return 'WAIT_A_MINUTE';
     } else {
         $gists = $this->gistFinder->getAll();
         $gistBackupHandler = $this->gistBackupHandlerFactory->getInstance($user, $gists);
         $zipPath = $gistBackupHandler->backup();
         return Response::download($zipPath, null, ['Set-Cookie' => 'fileDownload=true; path=/']);
     }
 }
Example #21
0
 function download()
 {
     $blocks = array_keys((array) \Larakit\Makeup\Manager::$blocks);
     $themes = ['default' => 'default'] + \Larakit\Page\PageTheme::getThemes();
     $pages = array_keys((array) \Larakit\Makeup\Manager::$pages);
     $contents = ['!' => public_path('!/'), 'packages' => public_path('packages')];
     $tmp_names = [];
     if (!is_dir(storage_path('makeup/'))) {
         mkdir(storage_path('makeup/'), 0777, true);
     }
     $digest = [];
     foreach ($pages as $page) {
         foreach ($themes as $theme) {
             $name = 'page_' . $page . '--' . $theme . '.html';
             $url = url('/makeup/frame-page-' . $page . '?theme=' . $theme);
             $content = $this->prepare_content($url);
             $tmp_name = storage_path('makeup/' . $name);
             file_put_contents($tmp_name, $content);
             $contents[$name] = fopen($tmp_name, 'r');
             $tmp_names[] = $tmp_name;
             $digest['pages'][$page][$theme] = $name;
         }
     }
     foreach ($blocks as $block) {
         foreach ($themes as $theme) {
             $name = 'block_' . $block . '--' . $theme . '.html';
             $url = url('/makeup/frame-block-' . $block . '?theme=' . $theme);
             $content = $this->prepare_content($url);
             $tmp_name = storage_path('makeup/' . $name);
             file_put_contents($tmp_name, $content);
             $contents[$name] = fopen($tmp_name, 'r');
             $tmp_names[] = $tmp_name;
             $digest['blocks'][$block][$theme] = $name;
         }
     }
     $tmp_name = storage_path('makeup/index.html');
     //        $tmp_names[]     = $tmp_name;
     file_put_contents($tmp_name, \View::make('lk-makeup::!.digest', ['digest' => $digest])->__toString());
     $contents['index.html'] = fopen($tmp_name, 'r');
     //        dd(compact('path', 'theme', 'url', 'content'));
     // Creates an archive.zip that contains a directory "folder" that contains
     // files contained in "/path/to/directory" recursively
     // Load Zippy
     $zip_path = storage_path(date('H_i_s') . '.zip');
     $zippy = Zippy::load();
     $zippy->create($zip_path, $contents, true);
     foreach ($tmp_names as $tmp_name) {
         unlink($tmp_name);
     }
     return \Response::download($zip_path);
 }
 /**
  * @param Store $store
  * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
  */
 public function getImage(Store $store)
 {
     if ($store->toArray() == []) {
         \App::abort(404, 'The API doesn\'t exist');
     }
     $imageUrl = "";
     $imageIndex = $store->img_url;
     if ($imageIndex != NULL) {
         $filePath = storage_path() . "/store_images/" . $imageIndex;
         return \Response::download($filePath, $store->title . ".jpg", ['Content-Type' => 'text/jpeg']);
     }
     \App::abort(404, 'The user doesn\'t have a valid image');
     return [];
 }
 /**
  * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\BinaryFileResponse
  */
 public function index()
 {
     if (\Input::get('l')) {
         LaravelLogViewer::setFile(base64_decode(\Input::get('l')));
     }
     if (\Input::get('dl')) {
         return \Response::download(base64_decode(\Input::get('dl')));
     }
     if (\Input::has('del')) {
         \File::delete(base64_decode(\Input::get('del')));
         return \Redirect::to(\Request::url());
     }
     return view('maxham-log-viewer::log', ['logs' => LaravelLogViewer::all(), 'files' => LaravelLogViewer::getFiles(true), 'current_file' => LaravelLogViewer::getFileName()]);
 }
 public function invoice($id)
 {
     $transaction = Transaction::findOrFail($id);
     if ($this->user->id == $transaction->user_id) {
         $pdf = storage_path() . '/invoices/' . $transaction->reference_number . '.pdf';
         if (file_exists($pdf)) {
             return Response::download($pdf);
         } else {
             return Redirect::to('clients')->with('error', 'PDF was not found.');
         }
     } else {
         return App::abort(404);
     }
 }
Example #25
0
 private function handleCommandReturn($commandConfig, $commandReturn, $categoryName, $entityName)
 {
     $commandType = $commandConfig->type;
     if ($commandType == "download") {
         // Return file
         return Response::download($commandReturn);
     } elseif ($commandType == "view") {
         // Return view; data is in $commandReturn
         $commandView = $commandConfig->view;
         return view($commandView, $commandReturn);
     }
     // Just reload
     return redirect()->route("cms.list", array_merge([$categoryName, $entityName], Input::all()));
 }
 public function getIndex()
 {
     if (\Input::get('l')) {
         L5Log::setFile(base64_decode(\Input::get('l')));
     }
     if (\Input::get('dl')) {
         return \Response::download(storage_path() . '/logs/' . base64_decode(\Input::get('dl')));
     } elseif (\Input::has('del')) {
         \File::delete(storage_path() . '/logs/' . base64_decode(\Input::get('del')));
         return \Redirect::to(\Request::url());
     }
     $logs = L5Log::all();
     return view('sl-dev-l5-log::index', ['logs' => $logs, 'files' => L5Log::getFiles(true), 'current_file' => L5Log::getFileName()]);
 }
 public function get_get($file_name = '')
 {
     if (!empty($file_name)) {
         $_public = path('public');
         $_data = Config::get('cms::settings.data');
         $_ext = File::extension($file_name);
         $img_mimes = array('jpg', 'jpeg', 'gif', 'png');
         if (in_array($_ext, $img_mimes)) {
             $_ext = 'img';
         }
         $_path = $_public . $_data . '/' . $_ext . '/';
         return Response::download($_path . $file_name);
     }
     return Response::error('404');
 }
Example #28
0
 public function download($token)
 {
     $e = Expiration::where('token', $token)->first();
     if ($e) {
         $expirationDate = Carbon::parse($e->expiration);
         $now = Carbon::now();
         if ($expirationDate->lte($now)) {
             return Response::download(public_path() . '/uploads/plugins/' . Setting::key('plugin_zip')->first()->value);
         } else {
             echo "Su enlace ha expirado, consulte con el administraor del sistema";
         }
     } else {
         App::abort(403, 'Unauthorized action.');
     }
 }
 public function download($id)
 {
     $book = Book::with(array('chapter' => function ($query) {
         $query->orderBy('order', 'asc');
     }, 'chapter.element' => function ($query) {
         $query->orderBy('order', 'asc');
     }))->where("id", "=", $id)->get();
     $view = View::make('pdf/result', array("book" => $book));
     $pdf = new TCPDF();
     $pdf->AddPage();
     $pdf->writeHTML($view, true, false, true, false, '');
     $filename = public_path() . '/pdf/test.pdf';
     $pdf->output($filename, 'F');
     return Response::download($filename);
 }
 /**
  * @param $form_id
  */
 public function getDownload($form_id)
 {
     Coanda::checkAccess('webforms', 'view');
     try {
         $form = $this->webFormsRepository->getForm($form_id);
         if ($form->download() && $form->download()->available()) {
             return \Response::download($form->download()->filename);
         }
         $file_name = $form->name . '-Submissions-' . date('d-m-Y-H-i-s', time());
         $this->exporter->exportToBrowser($form, $file_name);
         exit;
     } catch (WebFormNotFoundException $exception) {
         App::abort('404');
     }
 }