Don't loop through every file line. Use readfile instead, its faster. Instead of using a PHP script, to read and flush the file, it's more neat to rewrite the header using. This will keep a "nice" URL myfile. To make this more robust you could add HTML5 feature detection and if it's not there then use window.
Here's a different approach. I prefer rather than to rely on browser support, or address this at the application layer, to use web server logic. If you are using Apache, and can put an. Of course, you could put this in httpd. The FilesMatch directive is just a regex so it could be set as granularly as you want, or you could add in other extensions.
The Header line does the same thing as the first line in the PHP scripts above. If you need to set the Content-Type lines as well, you could do so in the same manner, but I haven't found that necessary.
For more information click here. In a Ruby on Rails application especially with something like the Prawn gem and the Prawnto Rails plugin , you can accomplish this a little more simply than a full on script like the previous PHP example.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. Ask Question. Asked 12 years, 11 months ago. Active 1 year ago. Viewed k times. If the Adobe Acrobat is not installed then it pop-up to the user for Downloading the file. Please tell me how i can do this? Improve this question. Rob W k 76 76 gold badges silver badges bronze badges.
Prashant Prashant Add a comment. Active Oldest Votes. Hyperlinks have been around since the dawn of the Web. The new attributes are: download , media , and ping.
The download attribute is new in HTML5. It supplements the existing href attribute by telling the browser that the resource the href points to should be downloaded directly, instead of visited which could happen with a file that the browser can open, like a PDF. The value of the download attribute is used for the name of the file that is downloaded.
Being able to have different values for href and download can come in handy. For example, you might need to generate unique files dynamically on the server for monthly or yearly reports on a per user basis, but still present the user with a meaningful filename for when they download a file.
You can use the HTML download attribute to specify that the target will be downloaded when a user clicks on the hyperlink. The download attribute is only used if the href attribute is set. The value of the attribute will be the name of the downloaded file. There are no restrictions on allowed values, and the browser will automatically detect the correct file extension and add it to the file.
You can also specify a value for the download attribute, which will be the new filename of the downloaded file. If the value is omitted, the original filename is used.
0コメント