Monday 15 March 2010

php - Auto-rename downloaded file based on page title? -


Actually, I want to put a link to download a .zip file at the bottom of each page. That. Inside the zip file I will have a PDF file.

The .zip file has been downloaded at any time, I want her title to be similar to the title of the page - plus, I want a PDF, for example, if they are titled "This My Page" If you download from a page, then the .zip file "This is my page .zip" and should be inside PDF "This is my page pdf". The PDF will have the exact similar content , even if it is downloaded from a page.

I am open to any solution, whether it is PHP, Javascript, HTML, etc.

When you use filename = in content-displacement

  $ actual_file_name = '/ var / yourserver / file Dynamically set the file name of the download.  

download_zip.php Zip '; $ Download_file_name = substr (str_replace (array ('\\ / | & gt; & lt;?% \ "*'), '_', $ _GET ['title']. '.zip'), 0, 255) ; $ Header ('expiration: 0'); header ('cache-control: required-modified, post-check = 0, pre-check = 0') mime = 'app / zip'; header ('Pragma: public' Header ('Content-Type:'. $ Mime); Header ('Content-Dispute: Attachment; File Name =' '$ Download_file_name' '' ';' 'Header (' Cash-Control: Private ', Wrong) ); / Header ('content-transfer encoding: binary'); header ('content-length:'. Filesypes ($ real_fie To get the page title of the last page, the easiest way is to possibly download the link (header: 'connection: close'); read file ($ real_file_name); exit ();

Will have to go through the title as a $ _ GET variable. From the page with the download link:

  & lt; a href = "http: // yoursite .com / download_zip.php? Title = The + Page + You + Were + Just + On "& gt; Download the zip file with the title of this page & lt; / a & gt;   

For this you have to include it To keep your page title in the Ga link, updating the page title in two places, try using a $ page_title variable in the page with the download link: < Pre> & lt ;? Php $ page_title = 'Page Title'; ? & Gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; & Lt ;? = $ Page_title? & Gt; & Lt; / Heading & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; A href = "http://yoursite.com/download_zip.php?title=<?= urlencode ($ page_title)?" & Gt; Download the zip file with the title of this page & lt; / A & gt; & Lt; / Body & gt; & Lt; / Html & gt;

No comments:

Post a Comment