Это видео недоступно.
Сожалеем об этом.

PHP File Download | Download Any File using PHP

Поделиться
HTML-код
  • Опубликовано: 15 авг 2024
  • Hello Guys
    Watch My Other Playlists:
    PHP : • Insert data into MySQL...
    NODEJS : • Node JS About it,How t...
    HTML & CSS: • Create Google Amp Stor...
    ================ SOURCE CODE===============
    LINK : www.dropbox.co...
    ===============================================
    In this tutorial have shown how to download any file with any extension using PHP. There are a few simple steps and a small script using which we can download any file easily.
    Hope It Helps!

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

  • @seanharricharan7602
    @seanharricharan7602 2 года назад +2

    Hope all is well.
    I tried implementing this with a CSV file instead but when the csv is downloaded, the HTML code is also printed. Anyone knows how to resolve this?

  • @srinivasanks2988
    @srinivasanks2988 Год назад

    A doubt,its work,without downloading image,i've tried downloading the php program file,but after downloading the notepad file, after i open, show a my wrote html file also, how to do it

  • @misnad
    @misnad 4 года назад +2

    When I tried it, it is downloading the download.php file, and not image .. plz help ☹️

    • @CodeFlix12
      @CodeFlix12  4 года назад +1

      Put anchor tag on image

  • @Sumonms
    @Sumonms 3 года назад +1

    it show "we don;t support this file format"

    • @CodeFlix12
      @CodeFlix12  3 года назад +1

      Which file format?

    • @Sumonms
      @Sumonms 3 года назад +1

      @@CodeFlix12 dear sir when download is complete the image i can't show its blank white

    • @CodeFlix12
      @CodeFlix12  3 года назад

      I am not getting it

  • @hritwikadubey3964
    @hritwikadubey3964 2 года назад

    what if I want to download the file in specific folder like "downloads"?

  • @mabasadailycode1781
    @mabasadailycode1781 3 года назад +3

    Thank you 🕺, but how do I set the content disposition if my file name contains special characters like &, + because I can’t download them though other files I’m able to. I would appreciate if you could help. Thank you 🙏

  • @poojabhatia247
    @poojabhatia247 4 года назад +2

    The source code gave me an Warning: Cannot modify header information - headers already sent, please could you help me resolving this error. Thank You!

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

      Did you use different headers than what are used in the code? Also, you mentioned warning, so is the code still running for you?

  • @julsco8701
    @julsco8701 4 года назад +1

    why i cant download my file? when i click the tag was always display a word in a different language? help me please for my capstone project. Godbless.

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

      Can you mail me screenshots! I might understand your problem in a more better way then. It is working fine for others including me so

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

      @@CodeFlix12 it wont work in cpanel. or it already upped.

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

      @@CodeFlix12 But it works in localhost. What's the problem with that?

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

      The problem is with the path given for the file in the cpanel then

  • @ashishsoni2431
    @ashishsoni2431 5 лет назад +2

    Really you are awesome bro......i appreciate it....😉

    • @CodeFlix12
      @CodeFlix12  5 лет назад +2

      I do everything for you all people who need solutions to problems easily. Thanks for always supporting and commenting! Appreciate a lot!

  • @samarthd.n.2314
    @samarthd.n.2314 3 года назад +1

    I know this video is outdated, but can you make a video on allowing to upload and download files of all sizes and types in php

    • @CodeFlix12
      @CodeFlix12  3 года назад

      It is not outdated sir, it still works. I already have a video on upload which works too

    • @____Boss_____
      @____Boss_____ 2 года назад

      @@CodeFlix12 No need of this much codes just a download attribute is enough

  • @rendyaditama3815
    @rendyaditama3815 3 года назад +1

    Very good tutorial, but the files that can be downloaded are only photos.
    document files such as (.pdf) and also compressed files such as
    (.rar) cannot be downloaded.
    can you tell me how to download (.rar) and (.pdf) files using php?

    • @CodeFlix12
      @CodeFlix12  3 года назад +1

      Try adding allowable extensions

    • @rendyaditama3815
      @rendyaditama3815 3 года назад

      @@CodeFlix12 how to add allowable extensions?

    • @CodeFlix12
      @CodeFlix12  3 года назад

      You can see it in the code

  • @ilhamfirnanda9482
    @ilhamfirnanda9482 4 года назад +1

    may i ask how to handle if file is cancel download and do something

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

      You can make a handleCancel function which works on click of cancel button

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

      @@CodeFlix12 can you make example please

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

      @@ilhamfirnanda9482 brother we just need to add a function for on cancel click

  • @getsetflycoding8865
    @getsetflycoding8865 3 года назад

    hey bro , when i download image and open it . it would not open and give not supported msg;

    • @CodeFlix12
      @CodeFlix12  3 года назад

      Just try for one of my videos and see
      Because I tried that
      If that doest work just check for the extension you are putting in code

  • @srinivasan000
    @srinivasan000 3 года назад

    download
    Download attribute html

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

    Dear brother is the procedure same if the download file is pdf not image

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

      Yes the procedure is same

  • @hwy419
    @hwy419 3 года назад +1

    Very helpful. Thank you!

  • @natnatmaglalang8472
    @natnatmaglalang8472 5 лет назад +1

    thank u a lot, your tutorials are so helpfull. and some tutorial about file management please , thank u a lot

    • @CodeFlix12
      @CodeFlix12  5 лет назад +2

      Yes i have made tutorials on file management you can check.. they are old.. if other than that u want any specific topic tutorial than u can comment here or mail me.
      Thanks❤️

    • @natnatmaglalang8472
      @natnatmaglalang8472 5 лет назад +1

      ah yess im already downloaded your tutorials about file managemet, can I ask, ,about sending files through gmal , because my thesis is about files management

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

      Yes I will try to built something like that! Currently I am working on another topic of file management.
      Hope that helps. Keep flixing 🙌

    • @natnatmaglalang8472
      @natnatmaglalang8472 5 лет назад +1

      thank a lot , more powers to come😊

  • @soumikbhattacharya8938
    @soumikbhattacharya8938 3 года назад

    Hello, this code perfectly works on localhost but not working on live server, can you please help regarding that.
    Output shows binary file.

    • @CodeFlix12
      @CodeFlix12  3 года назад

      The files are correctly uploaded on server?

    • @soumikbhattacharya8938
      @soumikbhattacharya8938 3 года назад

      @@CodeFlix12 yes correctly uploaded, with proper permission. But the problem is when i click download button, instead of downloading this file it's open in binary format.

    • @CodeFlix12
      @CodeFlix12  3 года назад

      Maybe try changing the extension of files

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

    after downloading, the image is not displayed. what should i do

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

      The path to the image might b wrong

    • @yudhawibowo777
      @yudhawibowo777 3 года назад

      Hello , for solutions this problem you can see my comment at the top. Thank you

  • @moesatt4145
    @moesatt4145 4 года назад +1

    This is a very helpful video.
    Can you please also help me do a tutorial "after the users key in their id (eg 001), users can download the files that I uploaded in the database according to the id"
    Thank you very much in advnace! :)

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

      Thank you

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

      CodeFlix do u have any suggestions for the tutorial I mentioned? Is it possible to do that?

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

      @@hmonmoesatt7092 hey! I dont think brother exposing the ID to end users is a good idea, it is possible but harmful

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

      ​in this case, what I mean by ID is just a unique number for them to get their own files ( I want my customers to download their files themselves instead of email to them) :D

  • @user-dz4qq7gv1w
    @user-dz4qq7gv1w 4 года назад

    tapi bagaimana cara kita linkkan agar file dapat di upload/download oleh setiap user tanpa di tampilkan ke user lain. sekali lagi terima kasih..!

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

      Can you translate it to English please

  • @yudhawibowo777
    @yudhawibowo777 3 года назад +2

    Thanks before for your video , but any little error after download file , as shown the file its can't be open with message : error format. and I have solutions for this , and bellow its my code and really working fine :
    $filename = basename($_GET['path']);
    $filepath = './assets/file/berkas/' .$filename;
    if(!empty($filename) && file_exists($filepath)) {
    //Definisikan Header
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.$filename);
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filepath));
    ob_clean();
    flush();

    readfile($filepath);
    exit;

    }
    I think the root cause problem is need to input header('content-length') because the size of file become increase if without that.
    Thank you.

    • @ConsulthinkProgrammer
      @ConsulthinkProgrammer 3 года назад

      Try this for additional reference
      WebApp - Login Form for Download Files
      ruclips.net/video/rkZj-Sk-XzQ/видео.html
      ruclips.net/video/2nyYtanYC4Y/видео.html

    • @kevinchristiancastillo2017
      @kevinchristiancastillo2017 Год назад

      WOW..thank you sir, helps me alot...also Thanks to the uploader of this video @CodeFlix...Godbless

  • @rhuzaifa
    @rhuzaifa 4 года назад +1

    This Is Not working in Opera Version:65.0.3467.78

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

      Is there any error coming or it is just not working

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

      Hi from my other account.
      My answer.
      No it does not give any error...
      I explain the situation below
      I have 2 files namely index.php and downloadexcel.php.
      In index.php i have a button which sends the session information to downloadexcel.php. The downloadexcel.php file gets the data from sql table and inserts into the excel file..
      The code runs perfectly fine in Chrome, Firefox and IE.
      But does not run in Opera.
      When i Launch Opera And Click On the download button it downloads the file but this works only one time in Opera. When i click on the download button again it does not download the excel file this time. When i restart opera it works again but for one time only.
      The headers i used in the downloadexcel.php file are as follows.
      header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') n
      header ('Content-Disposition: attachement;filename="name.xlsx"');

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

      What am i missing?
      Is there any cache problem for opera?

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

      Yes you are not missing anything. This is a browser related issue. Browser does not support this type of caching

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

      @@CodeFlix12 what would i need to do to run it on Opera. As this is my project for a collage course which requires the project code to be compatible with all the main stream browsers.
      Do i need to Change or Add A header?

  • @marcusaureliusregulus2833
    @marcusaureliusregulus2833 3 года назад

    Hey. I don't get explorer popup to choose download location

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

    And what have I to do when i have the image in a folder

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

      Thx bro i found the solution

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

      Sure sir

  • @user-oj2qy8iu6n
    @user-oj2qy8iu6n 2 года назад

    Is it possible to do the downloading in the background?

    • @CodeFlix12
      @CodeFlix12  2 года назад +1

      It happens in bg once you click download

  • @kriptoedits9978
    @kriptoedits9978 3 года назад

    Can we use this only for pics?

  • @debanjandey3267
    @debanjandey3267 3 года назад

    in ur video u mentioned image1.jpg ........ but what if I used a form and I wrote my name and thats the name of the jpg which immediately created in the folder....I mean to say u dont know when u r writing the code that whats the name of the jpg will be....... in that case what should I write in the blank space???
    click here

    • @CodeFlix12
      @CodeFlix12  3 года назад

      Just autofill it with php then

    • @debanjandey3267
      @debanjandey3267 3 года назад

      autofill???

    • @debanjandey3267
      @debanjandey3267 3 года назад

      can u plzz elaborate???

    • @CodeFlix12
      @CodeFlix12  3 года назад

      Bring the name from database and fill it
      It will be dynamic then

    • @debanjandey3267
      @debanjandey3267 3 года назад

      @@CodeFlix12 can I contact u in person... email or whatsapp!?

  • @rohanmp-rt1si
    @rohanmp-rt1si Год назад

    Thank lot sir,,,

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

    it will really help me , thanks dude

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

    Thanks for the lessons

  • @ShubhamPandey-st4nn
    @ShubhamPandey-st4nn 3 года назад

    very helpful. thanks a lot

  • @noah-tt2iv
    @noah-tt2iv 2 года назад

    can u give me link to download this php script

  • @gopinath-jd1tl
    @gopinath-jd1tl 2 года назад

    thank you sir

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

    how i can do it for an apk? Because i don?t get any error but it doesn't download anything

    • @CodeFlix12
      @CodeFlix12  4 года назад +1

      The file location of apk would be wrong sir!

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

      Sorry but it' s like in your video, it founds the file else i would have get an error. It doesn't start the download can you help me sir?

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

      Sir if the location of the file is wrong it won't give an error

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

      @@CodeFlix12 okay thank you, tomorrow i' ll check. 😊😊

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

      Sure sir

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

    thank you that was so helpful

  • @heythere_696
    @heythere_696 2 года назад

    thank you sou much it work 👌👍

  • @mikailsumenoglu548
    @mikailsumenoglu548 2 года назад

    readfile($filepath);
    over
    addding;
    ob_clean();
    flush();

  • @md.sagorahmed8925
    @md.sagorahmed8925 2 года назад

    thanks

  • @gavlorain3881
    @gavlorain3881 3 года назад

    I need upload mp3 . Can u help me tnx.

  • @fahadahmed1706
    @fahadahmed1706 3 года назад

    will it download the other php files?

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

    What not do do 101. WARING!!! excellent to download any file, I mean any system file!!! never trust user input, and make sure you just don't allow url params to decide full path of the file...

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

      True, but somewhere we have to give user flexibility

    • @MrDovanele
      @MrDovanele 4 года назад +1

      @@CodeFlix12 You just need to point those things out very clearly as most "new" people just copy code without realising it or just add comments inside code when showing example

    • @marcusaureliusregulus2833
      @marcusaureliusregulus2833 3 года назад

      Hey. I don't get explorer popup to choose download location

  • @cleversaid1966
    @cleversaid1966 4 года назад +1

    Thanks

  • @Paltibenlaish
    @Paltibenlaish 3 года назад

    will this work with 3 gb files?

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

    apk download is not working

  • @nadaah9
    @nadaah9 3 года назад

    Thank you so much for the concise video and explanation of how the codes work THANK YOU SO MUCH

  • @designmaster21
    @designmaster21 2 года назад

    Thanks Sir ❤
    You help me a lot 😍
    May Allah Bless you Ameen

  • @jasopakisan1771
    @jasopakisan1771 2 года назад

    Not working but thanks

  • @____Boss_____
    @____Boss_____ 2 года назад

    🙍

  • @expertkiller2121
    @expertkiller2121 3 года назад

    Please hindi