Page 1 of 1

help needed download image

Posted: Sat Dec 24, 2005 6:26 am
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]

Posted: Sat Dec 24, 2005 6:50 am
by Jenk
Images do not have a file type of "application/octet-stream"

image/jpeg
image/gif
image/png
etc.
:)

Posted: Sat Dec 24, 2005 8:03 am
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]

Posted: Sat Dec 24, 2005 8:13 am
by m3mn0n
Read the comments on this manual page: http://php.net/readfile


There is some examples that will help you.