How to Download Single File in Laravel

Поделиться
HTML-код
  • Опубликовано: 15 ноя 2024

Комментарии • 62

  • @bensonokello888
    @bensonokello888 7 лет назад +1

    Look at what I have been looking for for over three months.
    Instant subscription BONS

    • @bons281
      @bons281  7 лет назад +1

      Awesome to read this.
      Thanks a ton +Ben.
      :D Feeling blessed.
      Glad to have you on board!!

    • @bensonokello888
      @bensonokello888 7 лет назад +1

      The pleasure is mine. Am glad you shared this.

  • @greeshmay7122
    @greeshmay7122 6 лет назад +1

    hello... you r showing how to download file whic is located in databse ... but i want to download the result whic i got after performin a searchin g.. please help me .. thnaks in advance

  • @nooreekhayrattee1846
    @nooreekhayrattee1846 5 лет назад

    Very nice tutorial..works excellent for Laravel 5.6 as well

  • @anassourbiaa3302
    @anassourbiaa3302 4 года назад

    thank you very much bro , exxelent job !!

  • @husnithamrin4249
    @husnithamrin4249 7 лет назад +1

    for directory you can use $filedir = Storage::url('/maybe/custom/folder/inside/storage/app',$somevariable->attachment);
    inside controller

  • @aminqim2726
    @aminqim2726 6 лет назад +1

    nice tutorial.. can I know what is your data type for each colum

    • @bons281
      @bons281  6 лет назад

      +Amin Thank You.
      Datatype that I used here
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `file_title` varchar(200) NOT NULL,
      `file_name` varchar(200) NOT NULL,
      `created_at` timestamp NOT NULL,
      `updated_at` timestamp NOT NULL,
      u can also find the sql file in following link
      gitlab.com/Bons/download-files-laravel5/blob/master/download_db.sql
      for upload file, u can get idea from this video
      ruclips.net/video/LVipmYUakOU/видео.html

    • @aminqim2726
      @aminqim2726 6 лет назад

      thank you..

    • @aminqim2726
      @aminqim2726 6 лет назад

      can I store it on database as blob? and download the file?

  • @elziecrous9083
    @elziecrous9083 6 лет назад

    Thank you for an excellent tutorial!

  • @maninderbadwal3645
    @maninderbadwal3645 5 лет назад

    very nice video.its working

  • @ahsanshahid9240
    @ahsanshahid9240 6 лет назад

    Thanks buddy!!!
    Your video is very useful.

  • @mohammedsabbar3894
    @mohammedsabbar3894 6 лет назад

    Thanks that's very helpful for my

  • @horizondor9386
    @horizondor9386 6 лет назад

    I have a problem when i download file it appears whene i'm download it : failure: file not found
    what can cause the problem
    NB : i have all file stored on my database

  • @jovendev3933
    @jovendev3933 7 лет назад

    Hi, i need help here, instead of download single file, are we able to select multi files and download it?

    • @bons281
      @bons281  4 года назад

      Hey @joven sorry to help you that time, but if you still need then here is the video about multiple files download video
      ruclips.net/video/IA03QeE59Fk/видео.html

  • @PrabinPaudelComard
    @PrabinPaudelComard 7 лет назад

    it start the download but download fails.. what's the problem of it?

  • @Twinkletwinklelittlestar007
    @Twinkletwinklelittlestar007 6 лет назад +2

    I can't download file - but it's show on footer tab => Failed-No file

  • @menphors7733
    @menphors7733 7 лет назад

    Thank you so much

  • @moonlightteaa
    @moonlightteaa 7 лет назад

    when i click the download button, it show up and then said " failed- No file " i wonder what went wrong ?
    is it because of the path ?
    then my path will be Project/storage/app/public/upload/{{$user1->upload}} ???

    • @bons281
      @bons281  7 лет назад

      hi sorry, late reply.Hmm, I think it's happening because of the path. .in browser hold on the file and inspect and check what URL/path are u getting??is that match with your file location??
      Project/storage/app/public/upload/{{$user1->upload}} can't your path ur path will be like
      Project/storage/app/public/upload/filename.extension i means
      Project/storage/app/public/upload/mina.doc
      Project/storage/app/public/upload/appli.pdf

    • @greeshmay7122
      @greeshmay7122 6 лет назад

      hello even i have the same problem

  • @Thepando20
    @Thepando20 6 лет назад

    THX DUDE IT WORKS!

  • @medoune89
    @medoune89 8 лет назад

    Great tutorial can you add a counter to each download ....thanks

    • @bons281
      @bons281  8 лет назад

      +medoune cisse Many many thanks for your nice feedback...do you want to show counter with database or without database??

  • @rihansani6606
    @rihansani6606 5 лет назад

    hey bro good tutor tnx soooooo much and for those who have "failed - no file " error just just add"/" befor download in "href" like this
    td> Dowanload

  • @g.manikamnaidu2729
    @g.manikamnaidu2729 7 лет назад

    This code is working off line but not in live... when i click on download button then it returns Failed - No file, but in folder where i store the file i have it...

    • @bons281
      @bons281  7 лет назад

      hi +manikam do u check your download file path??? is it match with your actual path??go and check your file name by holding the mouse on the download icon or file, then right click and inspect.
      or can u share your live project link??

  • @IndraVManik
    @IndraVManik 7 лет назад

    hello sir. i have a problem when download file.
    can help to resolve about the problem.
    thanks

    • @bons281
      @bons281  7 лет назад

      +Indra
      Greetings from bonstutorial. We appreciate that you have knocked us for
      help. We would like to help you but before that we need to know your
      problem precisely. Please send us the necessary data and description of
      your problem. Thank you for being with bonstutorial , stay tuned.

  • @saurav1502
    @saurav1502 7 лет назад

    what if i store my file in app\storage of laravel instead of db how will i give the dir of that file..???

    • @bons281
      @bons281  7 лет назад

      Hi saurav
      suppose ur files are located in projectname/public/download directory
      in Controller
      public function downfunc(){
      $manuals = [];
      $filesInFolder = \File::files('download');
      foreach($filesInFolder as $path)
      {
      $manuals[] = pathinfo($path);
      }
      // var_dump($manuals);
      $vvs=json_encode($manuals);//for easy to display in view i encode
      return view('download.viewfile',compact(''vvs'));
      }
      in view
      @foreach(json_decode($vvs) as $mm)


      Download


      @endforeach
      Note:here {{url('/')}} is ur root url like projectname/public ..{{$mm->dirname}} is the folder name that is download,{{$mm->basename}} is the file name with extension like abc.jpg ..so along these three it stand projectname/public/download/abc.jpg

    • @saurav1502
      @saurav1502 7 лет назад

      thnks bt it is showing error ErrorException in CompilesLoops.php line 80:
      Undefined offset: 1

  • @omarmalikzada335
    @omarmalikzada335 6 лет назад

    what is that compact('downloads') at 3:33

    • @bons281
      @bons281  6 лет назад

      compact() is PHP function.Here Laravel uses it to pass variables from controller to its View.There are also other ways like 'with'
      consider our code
      $downloads=DB::table('downloadpdf')->get();
      return view('download.viewfile',compact('downloads'));
      1.first $downloads=DB::table('downloadpdf')->get(); we fetch the data from 'downloadpdf' table and put this data in $downloads variable
      2.then since we will use that $downloads variable in our view so we have to pass that ...so we used here compact function to pass data ...here compact('downloads') downloads is variable...but you have to careful when you will use compact ,do not use $ sign of variable .just use the rest part of the variable except $.
      return view('download.viewfile is our view that is download folder then viewfile.blade.php

  • @Twinkletwinklelittlestar007
    @Twinkletwinklelittlestar007 6 лет назад

    what is "{{$down->file_name}}" how did you get " file_name" , not " file_title " on database?

    • @Twinkletwinklelittlestar007
      @Twinkletwinklelittlestar007 6 лет назад

      Can I use same folder of files upload and download?

    • @bons281
      @bons281  6 лет назад

      in laravel here we are using blade temple that's why the file extension is .blade.php
      when you want to display data in blade view, u can wrap the variable in curly braces {{ }}
      $down->file_name is our variable ...$down is array which we passed from controller to view...to get only file_name we use $down->file_name...file_name is the table column name
      how did you get " file_name" , not " file_title " on database? i am confused about your second question...what is the actual problem ...can you explain your problem

  • @firojkhan-kv1ew
    @firojkhan-kv1ew 6 лет назад

    how we can upload pdf, doc and text files in laravel 5.5

    • @bons281
      @bons281  6 лет назад

      +firoj Check this link for upload ruclips.net/video/LVipmYUakOU/видео.html

  • @priyesh5235
    @priyesh5235 7 лет назад

    Hello Sir, I'm getting an error which is I'm not able to download the actual file it shows failed-No file...what should be the datatype of column in database for file upload?

    • @bons281
      @bons281  7 лет назад

      +priyesh here datatype of column file_name is string . do u inspect the download file??probably ur file href or full path is not right.i suggest you first try to inspect the download button and check if the source is right like yourpeoject/public/image/abc.txt
      u can also try this href="{{url('/')}}download/{{$down->file_name}}". like below

      Download

    • @priyesh5235
      @priyesh5235 7 лет назад

      well I have used LONGBLOB as datatype because I have to upload various types of file...in HeidiSQL it show the file in binary form....onclick download button now i get failed-network error...and in my project/public/downloads folder is also empty...

    • @priyesh5235
      @priyesh5235 7 лет назад

      And one more thing my foreach loop is not creating repetative values in download.blade.view folder...

    • @bons281
      @bons281  7 лет назад

      listen +priyesh it does not matter what the type of data...u just need to get the file name plus file's extnsion along with full path ..i mean ur file full path that is yourproject/which_ever_directory_you_put_your_file/filename.file_extention
      for foreach loop is not creating repetative
      u can test it in controller
      $downloads=DB::table('table_name')->get();
      var_dump($downloads);
      check what you get??

    • @priyesh5235
      @priyesh5235 7 лет назад

      would you share me link of your database for download...I will try to figure out from that still have the same problem so....

  • @andreikyledelossantos5518
    @andreikyledelossantos5518 7 лет назад

    how can you put file in database?

    • @bons281
      @bons281  7 лет назад +1

      Hi +Andrei.see the following links
      ruclips.net/video/LVipmYUakOU/видео.html (if you wanna know how to upload file that case)
      stackoverflow.com/questions/35428876/how-to-store-and-retrieve-image-contents-from-the-database-using-laravel (see the answer part here)
      www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx
      from above links hope you might get some idea.thanks

  • @taoufiqzeroual2516
    @taoufiqzeroual2516 7 лет назад

    Hi! that's me again !!
    when i click on Down load i get that erreur :
    NotFoundHttpException in RouteCollection.php line 145:
    and the url is :
    localhost/shareitbaby.io/public/index.php/up_file/74696.pdf
    but when i remove index.php in url it works .
    can you explain that. thanks !!

    • @bons281
      @bons281  7 лет назад

      because ur file is located in the directory localhost/shareitbaby.io/public/up_file/74696.pdf ...so when u use localhost/shareitbaby.io/public/index.php/up_file/74696.pdf it does find the file thats why giving error

  • @زاجللتعليمبرمجةالويب

    thank you

    • @bons281
      @bons281  6 лет назад

      It's my pleasure :d

  • @WeltonLSantos
    @WeltonLSantos 8 лет назад

    upload github friend :)

  • @Osteele
    @Osteele 7 лет назад

    Doesn't anyone speak anymore?

  • @jovendev3933
    @jovendev3933 7 лет назад

    hi i did follow the tutorial here for upload single file: ruclips.net/video/LVipmYUakOU/видео.html
    This only store the information for file title and file itself, it doesn't store the created_at info.
    Is that it is caused by array save issue?
    $data = array('file_title' => $filetitle,
    'filename' => $filename);

  • @mohammedsabbar3894
    @mohammedsabbar3894 6 лет назад

    Thanks that's very helpful for my