sayedsohail Posted August 19, 2007 Share Posted August 19, 2007 How to download file from hyperlink? -------------------------------------------------------------------------------- hi everyone, I successfully created a pdf file and stored the file name,location inside a table. Now i am showing the link on the page and when user click this link i wish to open this pdf file from the server on the user desktop in a popup window. $filelocation == http://locatiion/pdf/xyz.pdf i.e, echo "<a href='<?php $filelocation ?>'Click to open</a>"; Can someone help, how i should achieve this? Its bit scary when i read another thread about downloading big files, although my files are very tiny i mean 30kb in size. -------------------------------------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/ Share on other sites More sharing options...
phpknight Posted August 19, 2007 Share Posted August 19, 2007 PEAR has an HTTP_Download class. You might want to check that out. Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/#findComment-328173 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 create a download page download.php?file=pdf/xyz.pdf <?php forceDownload($_GET['file']); function forceDownload($archiveName) { $headerInfo = ''; if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } // Security checks if( $archiveName == "" ) { echo "<html><title>PDF - Download </title><body><BR><B>ERROR:</B> The download file was NOT SPECIFIED.</body></html>"; exit; } elseif ( ! file_exists( $archiveName ) ) { echo "<html><title>PDF - Download </title><body><BR><B>ERROR:</B> File not found.</body></html>"; exit; } header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/pdf"); header("Content-Disposition: attachment; filename=".basename($archiveName).";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($archiveName)); ini_set("memory_limit","32M"); readfile("$archiveName"); } ?> please note this is just an example Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/#findComment-328179 Share on other sites More sharing options...
sayedsohail Posted August 19, 2007 Author Share Posted August 19, 2007 Thanks madtechi for giving the sample code, last question how about if i just want to open the file inside the user browser, when they click the hyperlink? <?php $filelocation == http://locatiion/pdf/xyz.pdf i.e, echo "<a href='<?php $filelocation ?>'Click to open</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/#findComment-328191 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 should be simple hyperlink echo "<a href='<?php echo $filelocation'>Click to open</a>"; if its a PDF they will need the reader (IE Adobe Acrobat Reader) installed Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/#findComment-328198 Share on other sites More sharing options...
sayedsohail Posted August 19, 2007 Author Share Posted August 19, 2007 thanks madtechie, is there anyway i could check if acrobat reader is installed on the user computer and than open the pdf file in their browser. Also i am going to give the user a option to download the file with link using your download code. its great. Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/#findComment-328217 Share on other sites More sharing options...
plutomed Posted August 19, 2007 Share Posted August 19, 2007 should be simple hyperlink echo "<a href='<?php echo $filelocation'>Click to open</a>"; if its a PDF they will need the reader (IE Adobe Acrobat Reader) installed echo "<a href=\"".$filelocation."\">Click to open</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/#findComment-328218 Share on other sites More sharing options...
sayedsohail Posted August 19, 2007 Author Share Posted August 19, 2007 thanks madtechie and pluto, is there anyway i could check if acrobat reader is installed on the user computer and than open the pdf file in their browser. Also i am going to give the user a option to download the file with link using your download code. its great. Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/#findComment-328223 Share on other sites More sharing options...
plutomed Posted August 19, 2007 Share Posted August 19, 2007 No Idea I don't think you can Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/#findComment-328224 Share on other sites More sharing options...
sayedsohail Posted August 19, 2007 Author Share Posted August 19, 2007 once again thanks to both you, if anyone has got an idea, please pm me. as i am going to close this thread, since so many threads are open. Quote Link to comment https://forums.phpfreaks.com/topic/65706-solved-how-to-download-file-from-hyperlink/#findComment-328230 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.