CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.

YesSoftware Forums -> CodeCharge Studio -> Tips & Solutions

 Force download (jpg, pdf, mp3 etc.)

Print topic Send  topic

Author Message

Posts: 251
Posted: 04/17/2008, 11:46 PM

Normally, when you add a link to a file (such as .jpg, .pdf, .mp3, .avi etc.) and visitors click this link, the file will open in their standard web browser or with their standard media player. If you want to offer your visitors the option to download the file, you can take this steps:

Add a link on your webpage with this details:

Static text: Download
Static address: download.php

Source Type: Datasource Column
Parameter source: (column with download details in your MySQL table, like the URL of the file)
Parameter name: file

Source Type: Datasource Column
Parameter source: (column with filename in your MySQL table)
Parameter name: filename

Make a new page, named download.php, and add this code to the top of this page:

$file = $_GET['file'];
$filename = $_GET['filename'];
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$filename.";");
header("Content-Length: ".filesize($file));

Just my two cents,

The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL
View profile  Send private message

Add new topic Subscribe to topic   

These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit

Internet Database

Visually create Web enabled database applications in minutes.

Home   |    Search   |    Members   |    Register   |    Login

Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by  and YesSoftware, Inc.