Jump to content

Recommended Posts

On a web page, when you have a link to a .doc, a .xls, a .ppt, or a .pdf...the browser automatically opens the file either in that borwser window. I would like to write a script or something that would force a save as dialog box to pop up rather than automatically open the file. This occurs when the file type is a .zip or .exe

 

anyone have any ideas???

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/
Share on other sites

this is the code at the minute. as it stands once the link is clicked the pfd opens in the browser

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  

<!--Start of HTML in English Language-->
<html lang="en">

<!--Start of head-->
<head>

	<!--title of the page-->
	<title>Libra Seafoods - Terms and Conditions</title>
	<!--End of the title  page-->

	<!--CSS imports-->
	<style type="text/css" media="screen">
		@import url("/master.css");
	</style>
	<!--Favicon code -->
	<link rel="icon" href="favicon.ico" type="image/x-icon" />
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	<!--End of favicon-->

	<meta name="author" content="Andrew Muat" />
	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
	<meta http-equiv="content-language" content="en" />
	<meta name="description" content="Libra Seafoods Homepage" />
	<meta name="keywords" content="libra, seafoods, home, homepage, sea, see, fish, prawn, food, foods, seefoods, seefood, seafood, " />


	<!--End of CSS imports-->


    </head>
<!--End of Head-->

<!-- Start of Body -->
<body>


	<!--Start of top wrapper for the top menu-->
	<div id="wrapper">
		<?php
			include '../menu.php';
		?> 
	</div>
	<!--End of top menu wrapper-->

	<!--Start of header-->
	<?php
		include '../header.php';
	?>

	<!--End of header-->
	<!-- Start of Main Body Wrapper -->
	<div id="wrapper2">

		<!-- Start of Container -->
		<div id="container">

			<!--Start of main content area on the screen-->
			<div class="leftside">
			<h1>Navigation</h1>

			<?php
				include 'leftmenu.php';
			?>

			</div>
		  <div class="content">

				<h1>Terms and Conditions </h1>

				<p> </p>
				<p>Please select to download our full terms and conditions </p>
				<p> </p>


				<p><a href="terms/Libra%20Seafood%20Processing%20Ltd%20terms%20of%20business.pdf"><strong>Libra Seafoods Processing Ltd - Terms and Conditions of Business.pdf </strong></a></p>

				<p><a href="terms/Libra%20cold%20store%20terms%20and%20conditions.pdf"><strong>Libra Seafoods Processing Ltd - Cold Store Terms and Conditions.pdf</strong></a></p>
				<p> </p>
		  </div>
			<!-- End of Content -->


			<div class="clearbottom"></div>

		</div>
		<!-- End of Container -->

			<!-- Start of Footer -->
			<?php
				include '../footer.php';
			?>
			<!-- End of Footer -->

	</div>
	<!-- End of main wrapper -->
<div class="clearbottom"></div>
</body>
<!-- End of Body -->

</html>
<!--End of HTML-->

 

(edited by kenrbnsn to add


tags)

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/#findComment-494952
Share on other sites

Make a new file called something like getfile.php with the code:

$file = $_GET['f'];

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 

header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($file));

header( "Content-Description: File Transfer");
@readfile($file);

 

Then change your link to:

<a href="getfile.php?f=terms/Libra%20Seafood%20Processing%20Ltd%20terms%20of%20business.pdf">Libra Seafoods Processing Ltd - Terms and Conditions of Business.pdf</a>

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/#findComment-494996
Share on other sites

here is the output where i try the above?!

 

Warning: Cannot modify header information - headers already sent by (output started at C:\webs\test\about\getfile.php:2) in C:\webs\test\about\getfile.php on line 5

 

Warning: Cannot modify header information - headers already sent by (output started at C:\webs\test\about\getfile.php:2) in C:\webs\test\about\getfile.php on line 6

 

Warning: Cannot modify header information - headers already sent by (output started at C:\webs\test\about\getfile.php:2) in C:\webs\test\about\getfile.php on line 7

 

Warning: Cannot modify header information - headers already sent by (output started at C:\webs\test\about\getfile.php:2) in C:\webs\test\about\getfile.php on line 9

 

Warning: Cannot modify header information - headers already sent by (output started at C:\webs\test\about\getfile.php:2) in C:\webs\test\about\getfile.php on line 10

 

Warning: Cannot modify header information - headers already sent by (output started at C:\webs\test\about\getfile.php:2) in C:\webs\test\about\getfile.php on line 12

%PDF-1.5 %Çì¢ 5 0 obj <> stream xœí]Yo7–F%ñ‚$–,Ëî–“+Ù±¯ì¨R Y¬Ê, z0À`^ºá·ö<õL70@zÌÿ†¬*ò’ɪ+9 ¶_®jaq9<ëwÜÕUÓîjóßþøów¿û£Úýõÿîþ¸u?N›±ëvB »NÖ}Õ«ù©a÷ûÿ½ûø\#Uçžçç¦ÏìþøoËŸþz÷Ç»CÕ™ÓþûÏ?ìþå~µÑmê†z)woþr·®Æqm3k׶ªêÆn§ZQ5ýîÍwÿ´ÿà꺫T[÷Ãþëë¡ÒÏH±ÿè꺩Ùvû¯ÚªÖMˆýÑUSW’ãþ“«ë±j%†ý§W¢’cÛ«ýgW×}¥„hç‡^Œû;S3ª–Ýþíß̇:ý¡Öû}O7Pwb¦ÕºuÓtbÿªÑ=ë}ßká'wù3÷ësÝ”F¥\‹ªû^è1Õ•”ã ÚýÓHÇVïË«¾eÛú£uUjck§¢Qrÿફơ½îŸnKÉÆïß'WíPWªoÿóÍ¿ßÕ—[}½wӯݛÿz?¯·1¯nZë÷Szë¤úžRoqZÿõf×Í Yk_7¿oÑìúÝOÿ}÷/7åÚjÇÖ~ó?˜åè.õ^³<Óþq‹<¿¤¿Óîô )Ñõî;Ý`…ƒèªAì”îHG²Aÿ¥§¶7”ÑêeîE3Q†^]1(½4c%ûNH³â²š^šIjõí¦n5i¸'?Óó=¨¾QúIÝR7ªNjâ°õÊêUЫ­ÉǼ֕4OÐk÷Ì:Mš¼W÷¨­ ûÚý©7]ÛtüÃÞÚ’DÕmËŸøœÞûÂkl™„{Óý¦m[ö16I÷ùO)ÌÂQJ[wíNŽ0”¢oìÄjBÉ,`'†ÊŠ[@=»êªZ©?ꨫUõ;U›}C7ÿq÷Í«?émbö‘ÞòÞzDM3è-s4‘—nXð†õwÛZ5Œ[ÏÏf^ôÚ Ã>ºjÌÕ~Ô´ãš>š¶µTšÙ|Bj’jô”†\7šÐÔØë÷µ#úƉy½×·?2¯·­lFM/¦­fKw憤^˯d­G­z·ƒ¨wR Óüëm˜‘™ÊFh>4ìúQÚÉÔtVàZjŽYkf¡™í0̳…&zÔWõ4µì§)Ò< ÓStîó9´#?¡ûéþ)ý|d~6µ¡ÍSšÅ£+³éz5ñì¾’C×õû3º<÷EïðÇtñ‰aïš·6泶ì¢÷¾û¹t@i6ú÷ÖLTŽòô€!ÇJ5ûßÎí Mk¶¥ž\%e»?§=5]ÓM+>ʯfªèõþš iÚ] U­çVðI¸pƒÄÝÍͲyÔ›Oûè%¼ÿQí£¹ÿRéùß?¢O=ÓÖòWOÊC÷ä|ò‚®>wÍ?§‘°ž°þ±QQ§p«D/ßÐö<Ÿ{5Þ«ø~‚^òã?›ˆ¤éµN!”å4/¦û­–¼¶Sýþ%õé‰ùP§×ùíÎþE´fúC÷gBëµü?u}bO²ož±•[䈞|{E­~53BeÆäºú\Kp½ójÅ—gYÕ[b”BÑ Ø<½¢†h /£×»Ž²Þ½p·Y¨›Ë*ôš3SC>éÇ_g=f“÷ÚvÞ{gY¹38ɬŸßj¥C÷Hx4Æ~>žiDȪUƒ¥šÄ#>L@tÿÙÌ1âÝÆïû°};ጅÓ/ì©{ôÄÎ^iAøä!=¦wÐŒ-;u¬ýÛZ®êv¯×í¨õæfà²í‚˜òsÇ©ŸGBÈÜ¿¤ŸŒkœ¦÷ÕtŸo짌mYãö€â¼Ægvþcn XÇ •ŸVb›>7p«Ê^#Æ}QááÄ¢Ù°HN¿‚“å1ÛÖÁD¾¶zÝõ8/'–Ìߚ͢GÐwvfÏœó˜ë–<Áìz¸E2E‚å! æWœàeË~éšVmáÇräÝcâöµ»Û‡ï¿BfdwŒÉÞõÏk4Ø×úÉÞ¦½M…ËpÌ©'0MýÐ[–ë1rËA<žå~{= ivºÿ ­”¶Œ'¯gôÙ)Užð¹DÛŸ5z‚D}ÉS÷IMR wW×J›(BsÐ 50éŠ}#þ>ãàÏÝøÂIQg¨BAžéÞ¿¯EÍÐ÷}ãñL+›u¿€þ¶’{†ªT†yª0O³($ÀØœd˜g8'\›‚ÖMÙ#DF'H×âj“}çœn35ý|Mš—ØžFí‹ì¦ê;µEd3ÿ•³è—yô· ·†âŒÛ32;¡YQéÂ홸È#üQ÷ÒgQ¥lÝÀŽÞ7K¶ }ž™õGLÄÁ¤Fx×°w z[=•8 ÉŠ4áç£ÙKÛÞÆDûz¡“ ³1Tb–Vc>ìkR)wÑ!¨Xýb·‰á!}•mîÔÇ*áÃHçØš`s ˆ¬O“1WkuœQvdË]¶Vád?æ=›ÄÍÏQóŒ]–”qú|Êšù™¾%{bhîQRû1=zrÃ^ì¨'‰eïc«Œös¢e„.C, ¿ATæÚÄïÐŒVÈäÅäH“ÇV ;,¢ulÚ1 «ªÓOn¢x&È åv'œÖK."æ¿çy6| n”Â)òÙ^ŠEFêjþŽñ`8 kScK%S†ˆ´¸ä†Ô ©ˆ* BÒrb÷˜¯c@À(4¢óBÝKß0Ö’`5~“e­­šÒ‰ér¢•Æ—‚ã—½#a Ü*å-¼ŽBW#%ɤp6V "o]:GWQL¿l$wèí—¸I(>œsÈqZP‚¯ÄmYlºíZM)Gô8[ÏCs¬é‘¥÷D ”.#ۜġ^ Bs½¨Ë…©–$¡N‘Ë’a1*ŠA§tA0*IªÆõ}ÙÕ«ÞŸ¤›ß£B9ÞåâÉ“'–òÉŽÌd;KSì¥ã\³¬¤RΟ‚Wý¡¸1¸Øyn2¼…j¤O)Àup;ëé’£ÉܹB“¡ÄCt÷׿þõ7OZûµ ï?Š3‹‘c®ÏO´1]êŠÞÇ8€nÙÖ üØ3³ÉÒ,Ž´ÅÈL‹&Ò«×5>J‚HVN¤¾“›£nðÜÁ¹ Gù~zUwÀu´>ãž…J3äº{€B z˜Ú¯ïk¸Ž7"1:^éP/¼£|:Ã…(^ø÷&úö9:½ö×.âÖ›ŠÿA\'ìÎV¹Î$Kº+à¡÷@D›^õøÒNK~;¬]

š’ ` ¹SØÖ™l6'8»ƒPó6‹…·G_Ì“ ßç¡I‡‚¸Z„J½>0¾E¢”¥¿Ë9g|sdFfð#Ô¡¸Ô1&É,zMF希¼*÷B,ºc_%+ºÖb|ýP¿<ñÛO£ÿ~eÖ¬›kKuçÙÓæ§"¯¬ôóoé¯ÛVÚO[êâÿuqåÿ±û5xL6î—ðþìòO Hߦo³ÏŜ̛àþ¡Z8!æ‰ýÒ¼_¾–¾–Ÿ–O)×*'M¹¦Ÿàý­9ǼÛB-Ï°ÛZþ¯û_÷¿îÝÿ7n`ß‘âõìdQ%:›+cçÔΘ?¯ìê¹\Ƃʪ꼊1Ó ‚ ³êógO.¯û§ÿ)öÿÏÅCƒQòŒ?Òb1, +±Íc9æ@-Ì€ù0Êàj˜‹üË€P U˜ôçAŒéPAXYPù0&C9Ô+ f± "ئ®^Ù|ovóêÕ­7ÖzÝ2†¤‡ýþô¿yÉßo^€ ±ïu ýe;yÆ^ðÿð/º!è!æ0Àñ5ÿ øÎ óÖ@aä0ˆ@øïwŠÿ|V೟WÐp2Àö-øžØßΞÂÛЂý7#”"¬f@ïV…s’±½ëŠq«qú/.v.(½áƒGÛŠ¿oü óF~Ξ}mωöÞ-Åä3,4d¯ÿ :A<× endstream endobj 47 0 obj <>stream PScript5.dll Version 5.2.2 ()Andrew endstream endobj 2 0 obj <>endobj xref 0 48 0000000000 65535 f 0000033080 00000 n 0000375273 00000 n 0000032991 00000 n 0000032249 00000 n 0000000015 00000 n 0000009042 00000 n 0000033170 00000 n 0000311532 00000 n 0000033280 00000 n 0000335572 00000 n 0000342860 00000 n 0000335917 00000 n 0000346970 00000 n 0000336706 00000 n 0000363500 00000 n 0000033211 00000 n 0000033241 00000 n 0000334931 00000 n 0000032433 00000 n 0000009062 00000 n 0000017634 00000 n 0000334985 00000 n 0000335015 00000 n 0000335054 00000 n 0000032619 00000 n 0000017655 00000 n 0000026504 00000 n 0000335097 00000 n 0000335127 00000 n 0000335166 00000 n 0000032805 00000 n 0000026525 00000 n 0000032228 00000 n 0000335332 00000 n 0000337119 00000 n 0000335209 00000 n 0000335239 00000 n 0000335278 00000 n 0000337319 00000 n 0000343076 00000 n 0000347177 00000 n 0000363710 00000 n 0000335486 00000 n 0000335798 00000 n 0000336342 00000 n 0000336976 00000 n 0000373785 00000 n trailer << /Size 48 /Root 1 0 R /Info 2 0 R /ID [] >> startxref 375513 %%EOF

 

any thoughts as to where ia mgoing wrong??

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/#findComment-495748
Share on other sites

Warning: Cannot modify header information - headers already sent by (output started at C:\webs\test\about\getfile.php:2) in C:\webs\test\about\getfile.php on line 5

 

you are ouputting content/data to the clients browser before line 5.

 

give us the exact file "getfile.php"

 

i believe the erroneous output is on line 2.

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/#findComment-495752
Share on other sites

I stupidly had a space before i opened my php tags, for some reason this kicked up that error. i have removed the gap and it is working perfectly now! Thank you all for your help!!! to be honest it wouldn’t be the end of the world if i didn’t get it working but it became a matter of principal that i did!!!!!

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/#findComment-495756
Share on other sites

likely specific server confgurations are giving fatal errors in your script that the webserver has been configured not to show.

 

try either of these 2 lines at the top of your script:

 

ini_set("error_reportin","E_ALL");

or

error_reporting(E_ALL);

---

show us what it says,

 

 

if its still a blank page then you will need to either;

 

a, go into apache logs file "error.log",

or b, place "exit('got this far');" at the top of the script, and then move it down and refresh, check if it shows, then move it down & refresh again etc til it does not show, you can find the errored line this way.

---

 

also give us ya script so far ;)

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/#findComment-495761
Share on other sites

nothing came up when i added the 2 error lines.

here are my 2 scripts as they are now

 

getfile.php

<?php
error_reporting(E_ALL);
$file = $_GET['f'];

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 

header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($file));

header( "Content-Description: File Transfer");
@readfile($file);

?>

 

Terms.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  

<!--Start of HTML in English Language-->
<html lang="en">

<!--Start of head-->
<head>

	<!--title of the page-->
	<title>Libra Seafoods - Terms and Conditions</title>
	<!--End of the title  page-->

	<!--CSS imports-->
	<style type="text/css" media="screen">
		@import url("/master.css");
	</style>
	<!--Favicon code -->
	<link rel="icon" href="favicon.ico" type="image/x-icon" />
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	<!--End of favicon-->

	<meta name="author" content="Andrew Muat" />
	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
	<meta http-equiv="content-language" content="en" />
	<meta name="description" content="Libra Seafoods Homepage" />
	<meta name="keywords" content="libra, seafoods, home, homepage, sea, see, fish, prawn, food, foods, seefoods, seefood, seafood, " />


	<!--End of CSS imports-->


    <style type="text/css">
<!--
.style1 {font-weight: bold}
-->
        </style>
</head>
<!--End of Head-->

<!-- Start of Body -->
<body>


	<!--Start of top wrapper for the top menu-->
	<div id="wrapper">
		<?php
			include '../menu.php';
		?> 
	</div>
	<!--End of top menu wrapper-->

	<!--Start of header-->
	<?php
		include '../header.php';
	?>

	<!--End of header-->
	<!-- Start of Main Body Wrapper -->
	<div id="wrapper2">

		<!-- Start of Container -->
		<div id="container">

			<!--Start of main content area on the screen-->
			<div class="leftside">
			<h1>Navigation</h1>

			<?php
				include 'leftmenu.php';
			?>

			</div>
		  <div class="content">

				<h1>Terms and Conditions </h1>

				<p> </p>
				<p>Please select to download our full terms and conditions </p>
				<p> </p>

				<p><span class="style1"><a href= "/about/getfile.php?f=terms/Libra%20Seafood%20Processing%20Ltd%20terms%20of%20business.pdf">Libra Seafoods Processing Ltd - Terms and Conditions of Business.pdf</a></span></p>
				<p> 
    
				  <strong><a href= "/about/getfile.php?f=terms/Libra%20cold%20store%20terms%20and%20conditions.pdf">Libra Seafoods Processing Ltd - Cold Store Terms and Conditions.pdf</a></strong> 
				    
				</p>
				<p> </p>
		  </div>
			<!-- End of Content -->


			<div class="clearbottom"></div>

		</div>
		<!-- End of Container -->

			<!-- Start of Footer -->
			<?php
				include '../footer.php';
			?>
			<!-- End of Footer -->

	</div>
	<!-- End of main wrapper -->
<div class="clearbottom"></div>
</body>
<!-- End of Body -->

</html>
<!--End of HTML-->

 

 

(edited by kenrbnsn to add


tags)

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/#findComment-495765
Share on other sites

i have removed the @ symbol and i am still gettin the blank page when i click on the link

 

http://www.libraseafoods.com/about/getfile.php?f=terms/Libra%20Seafood%20Processing%20Ltd%20terms%20of%20business.pdf

 

the above is what is displayed in the browser address bar on the blank page. i dont think i do have access to server error files. however i am lookin into it now

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/#findComment-495774
Share on other sites

getfile.php

 

<?

$file = $_GET['f'];

 

header("Pragma: public");

header("Expires: 0");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

 

header("Content-Type: application/force-download");

header( "Content-Disposition: attachment; filename=".basename($file));

 

header( "Content-Description: File Transfer");

 

header('Accept-Ranges: bytes');

header('Content-Length: ' . filesize($file));

 

@readfile($file);

?>

 

error in browser

 

<? $file = $_GET['f']; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".basename($file)); header( "Content-Description: File Transfer"); header('Accept-Ranges: bytes'); header('Content-Length: ' . filesize($file)); @readfile($file); ?>

 

any thoughts??

Link to comment
https://forums.phpfreaks.com/topic/96678-save-as-dialog-box/#findComment-495781
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.