help needed download image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ahtasham82
Forum Newbie
Posts: 10
Joined: Fri Jan 14, 2005 10:42 pm
Location: PAKISTAN
Contact:

help needed download image

Post by ahtasham82 »

Sami | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


hi,

i want to download images from my site i am writing this code

Code: Select all

<?
$filename = $_GET['imgname'];
$filepath = $_GET['imgpath'];

$size = filesize($filepath);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$filename);
header("Content-Transfer-Encoding: binary\n\n");
header("Content-Length: ".$size);
?>
but its downloading a html file plz help where i am wrong.......

hope to hear very soon.


Sami | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Images do not have a file type of "application/octet-stream"

image/jpeg
image/gif
image/png
etc.
:)
ahtasham82
Forum Newbie
Posts: 10
Joined: Fri Jan 14, 2005 10:42 pm
Location: PAKISTAN
Contact:

Post by ahtasham82 »

Sami | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


nope still not working.......

look at the code.....

Code: Select all

<?
$filename = $_GET['imgname'];
$filepath = $_GET['img'];
$sid = $_GET['sid'];

$size = filesize($filepath);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: image/jpeg");
header("Content-Disposition: attachment; filename=".$filename);
header("Content-Transfer-Encoding: binary\n\n");
header("Content-Length: ".$size);
?>
in $filepath i have the value "prodimages/imagename.jpg"
where prodimage is a folder in my site where the images r placed and the file with the download script is in the root of my site same as the prodimages folder.

im getting the size to but its not downloading instead image it downloads a html file

plz advise and correct...


Sami | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Read the comments on this manual page: http://php.net/readfile


There is some examples that will help you.
Post Reply