CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 How to force download jpg

Print topic Send  topic

Author Message
Markie


Posts: 251
Posted: 04/16/2008, 2:18 AM

Hi,

I'm building a photo gallery. Now I want to have an option to download a photo. I have made a link to the page download.php.

download.php contains:

<?php
$file = '{phdownload}';
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="{dlname}"');
@readfile($file);
?>

On my main gallery, I have this link with each photo:

<a href="download.php?dlname=dlname&phdownload=phdownload">Download</a>

In my MySQL dbase I have columns dlname and phdownload

It's not working at all.

What's the best method to force download jpg ?

Thanks,

Markie
_________________
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
Markie


Posts: 251
Posted: 04/16/2008, 4:08 AM

I have found a solution and thought maybe it's of use for fellow cc studio users:

In my gallery, I have made this link:

Static text: Download
Static address: download.php

Parameters:
Source Type: Datasource Column
Parameter source: (column with download details in your MySQL table)
Parameter name: file

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

Then I have made a separate page with the name download.php. I have added this code to the top of this page:

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

I think this is the right solution

Markie
_________________
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
mamboBROWN


Posts: 1713
Posted: 04/17/2008, 8:26 PM

Markie
Do you mind posting this in the Tips&Tricks forum? Thanks.
View profile  Send private message
Markie


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

Hi Mambobrown,

no problem
_________________
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 http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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