Hello friends, please how do i create a download link through which once my visitor click on the product or the download link they will be able to download files like MSWord format, PDF format, Audios and Videos. Regards, adsegzy
I use this <a href="<?=$link?>">Download</a> Not that i'm an expert, but on top of the page where the $link? stands for and what he should do.
you can use this code in a page and call it from link. header('Content-type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="lamp_portfolio.pdf"'); // The PDF source is in original.pdf readfile('1.pdf'); Regards, kadmine
You just point to the file on your website. Such as: http://www.example.com/files/writer.doc or http://www.example.com/files/program.rar Some the browser will try to open some types of files from within the browser such as the pdf files or image files in which case kadmine's idea would be useful.
kadmine has shown you a way! I will show you another, based on that approach! What we would do here is force the browser to download whatever it has! We would create a file download.php... And would place files inside different folders where the download.php resides... have a look at the screenshot... Now for downloading we would pass the URL like this: And here is the code inside the download.php file! <?php $file = $_GET['file']; //Get the file from URL variable $file_array = explode('/', $file); //Try to seperate the folders and filename from the path $file_array_count = count($file_array); //Count the result $filename = $file_array[$file_array_count-1]; //Trace the filename $file_path = dirname(__FILE__).'/'.$file; //Set the file path w.r.t the download.php... It may be different for u header("Content-disposition: attachment; filename={$filename}"); //Tell the filename to the browser header('Content-type: application/octet-stream'); //Stream as a binary file! So it would force browser to download readfile($file_path); //Read and stream the file ?> PHP: That;s it! Although I would recommend storing the file information inside database and then collect the information from download.php for a better security!
Instead of readfile try fopen,fread in small increments. I find this helps when using PHP to stream large files, a 2GB file would just about crash PHP when using readfile
I just showed a possible way! But to tell you the truth, I find it really stupid to pass the file location as URL variable! That should reside on some database for better security
Or just encode the file location, so all the user shall see is download.php?file=354865843= (example) and then on download.php, decode the $_GET['file'] to make it usable...you'll obviously have to create a function to encode/decode the file location. (consider using a variation of php's internal functions)
Thank you all for your assistance, i really appreciate it a lot. pls is there any where i can be voting for you on your contributions because i have seen other forums where by once the members contribution is of help to you, you can just click on a button to vote for that person. i have search this forum if there is anything like that but i could not find. in case there is any way pls tell me because i want to be showing my heart of appreciation.