
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to raise a "File Download" Dialog Box in Python CGI Programming?
Sometimes, it is desired that you want to give option where a user can click a link and it will pop up a "File Download" dialogue box to the user instead of displaying actual content. This is very easy and can be achieved through HTTP header.
For example, if you want make a FileName file downloadable from a given link, then its syntax is as follows −
#!/usr/bin/python # HTTP Header print "Content-Type:application/octet-stream; name = \"FileName\"\r\n"; print "Content-Disposition: attachment; filename = \"FileName\"\r\n\n"; # Actual File Content will go here. fo = open("foo.txt", "rb") str = fo.read(); print str # Close opend file fo.close()
- Related Questions & Answers
- How To Raise a "File Download" Dialog Box in Python?
- Raise a "File Download" Dialog Box using Perl
- How to download image using Python CGI Programming?
- Save File Dialog Box in Tkinter
- Access to file download dialog in Firefox in Selenium.
- How do we do a file upload using Python CGI Programming?
- How to print "Hello World!" using Python?
- "static const" vs "#define" vs "enum" ?
- How to create "next" and "previous" buttons with CSS?
- How can I do "cd" in Python?
- How does underscore "_" work in Python files?
- How to do CGI programming in Python?
- Difference between a "class" and an "object" in Kotlin
- How to create a "coupon" with CSS?
- How to create a "card" with CSS?
Advertisements