473,569 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Force a file to download using php

17 New Member
I have a html file on my server, if a user clicks on a link it should download, but instead it opens up in browser window

coding for downloading

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo $todayis = date("l, F j, Y.") ;
  3.  
  4. $id1 = $_POST['id'];
  5. header('Cache-Control: public');
  6. header('Content-Description: File Transfer');
  7. header('Content-disposition: attachment; filename=pm/'.$id1.'.html');
  8. header('Content-type: application/force-download');
  9. header('Content-Transfer-Encoding: binary');
  10. readfile('pm/'.$id1.'.html');    
  11. ?>
Its work fine in localhost but in server it opens up in new browser window, Any help would be useful

Regards
Zabiullah
Mar 25 '11 #1
1 2024
johny10151981
1,059 Top Contributor
follow the link. It might help you

and @ use before readfile() function
Mar 26 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1991
by: Navin | last post by:
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel" response.AddHeader "content-disposition","attachment; filename=" &" & StrFileName Now the it works fine in ie5.5 sp2 but no ie5.5 sp1 it prompts the user twice the open dialog box.
1
4919
by: Navin | last post by:
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel" response.AddHeader "content-disposition","attachment; filename=" &" & StrFileName Now the it works fine in ie5.5 sp2 but no ie5.5 sp1 it prompts the user twice the open dialog box.
3
10133
by: BOHICA | last post by:
I would like on my page when users click one of my mp3 files for the dialog box to pop up so they can choose to save the file to disk instead of trying to open through IE, but the dang thing won't do it. Is there script I can plug in without having to do asp or pl files? (Cobalt server does not allow these files) here is an example <a...
1
4826
by: Yanick | last post by:
Hi all, I'm creating an application for our needs and I want to make something using JavaScript, but I don't know how. Hope somebody will be able to give me hints on this. When I click on a button, I want to start a file download. When I click on the button, a new window open then the file download box appears. I want to automatically...
4
21929
by: Kevin Muenzler, WB5RUE | last post by:
How do I force a browser to download a file instead of displaying it? In other words I have a page with MP3 and WMA files on it and I would like for the visitor to download the file instead of play it without having to right-click and save. How can I force the browser to pop up the "save file as" dialog box instead of playing it? I know...
2
4675
by: Ole Hanson | last post by:
Hi It seems to be virtually impossible to perform a download of more than 2 files at the time from any website? The same limitation seems to be put on IE, if I'm using that as Client. I want to create a simple download manager, that can perform mayby 25 downloads at the same time. What presents the limitation? The WebClient class or the...
0
1460
by: karups | last post by:
hi, Can some one help me out? How to Force file download box when clicking on a link for a .pdf file. Normally it opens the pdf in IE itself, instead it should ask for (open , save and cancel) Similarly , also clarify that, is there any other method other than Response.Redirect(filename) to download a file. If so what it is?
4
3098
by: L. Scott M. | last post by:
I am invoking a file download using the following code: Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadFile.Name); Response.AddHeader("Content-Length", downloadFile.Length.ToString()); Response.ContentType = "application/octet-stream";
2
2163
by: skulka3 | last post by:
Hello, I want to implement file downloads inside an authenticated web page, such that when a user clicks a link, the server side python code connects to a ftp server, downloads a relevant file and then streams the file to the browser for the user to open it with the appropriate application. In this case it will either be a pdf or a tiff...
6
4380
by: ziycon | last post by:
I'm wondering if its possible to force a file to be downloaded when you go to a certain page. Say if you click on the link for the page and then it will go to that page and give you the prompt box to save or download the file?
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.