Page 1 of 2

header problem (content-disposition)

Posted: Sun Feb 16, 2003 4:58 pm
by s3rg1o
hey guys, I am trying to prevent leeching on my server so I am attempting to get content disposition to work and I am having no luck

Code: Select all

<?


header('Content-type: image/jpeg');
header('Content-disposition: attachment; filename=logo.jpg');




?>
the logo.jpg is not loading it just comes up with the red x

same if I do

Code: Select all

<?


header('Content-type: image/jpeg');
header('Content-disposition: attachment; filename=/home/web/pcgm/images/logo.jpg');




?>
and

Code: Select all

<?


header('Content-type: image/jpeg');
header('Content-disposition: attachment; filename=/images/logo.jpg');




?>
where am I supposed to put the files??

Posted: Sun Feb 16, 2003 5:17 pm
by Stoker
using header() only creates headers, so all you are telling the browser is what that the filename of the content is, you'll have to open the file and output its content, make sure the file and string handling functions you use are binary safe! (I would have used perl for such)

Posted: Sun Feb 16, 2003 6:28 pm
by s3rg1o
ok so what else do I have to add so that it will output the file?

Posted: Sun Feb 16, 2003 7:42 pm
by volka
let's assume you have a file somewhere (e.g. /home/me/images/logo02.jpg) and you want to distribute it as logo.jpg.

Code: Select all

<?php
header('Content-type: image/jpeg');
header('Content-disposition: attachment; filename=logo.jpg'); 
readfile('/home/me/images/logo02.jpg');
?>

Posted: Sun Feb 16, 2003 8:11 pm
by s3rg1o
ok good good, I like that but what if I want the image to show?

basically I wanna do this

http://www.pcgamemods.com/forums/attach ... ostid=9031

Posted: Sun Feb 16, 2003 8:36 pm
by volka
do not put it into the attachment ;)

Code: Select all

<?php
header('Content-type: image/jpeg');
readfile('/home/me/images/logo02.jpg');
?>

Posted: Sun Feb 16, 2003 8:56 pm
by s3rg1o
yes! THANK YOU VOLKA! :D

Posted: Sun Feb 16, 2003 8:59 pm
by s3rg1o
ok umm last question..

Code: Select all

<?php 
header('Content-type: image/jpeg'); 
readfile('/home/web/pcgm/images/logo.jpg'); 
?>
but what if I want to output something before the image? I can't put anything before the header or else it will not work and if I put something like

Code: Select all

<?php 
header('Content-type: image/jpeg'); 

echo 'hello';
readfile('/home/web/pcgm/images/logo.jpg'); 
?>
the image will not show

Posted: Sun Feb 16, 2003 9:19 pm
by volka
right, the html is one document and the image is one document.
Only one document per request. Not a limitation of php.

Posted: Sun Feb 16, 2003 9:34 pm
by s3rg1o
so essentially your saying I am screwed in that aspect

Posted: Sun Feb 16, 2003 9:58 pm
by Stoker
It's the nature of HTML, you link to images with <img> tags, they are never stored in the same file...

Posted: Sun Feb 16, 2003 10:18 pm
by s3rg1o
guys I need to hide my image links I am about to open a image hosting site and the last thing I need is plethoras of people raping me of bandwidth

Posted: Sun Feb 16, 2003 11:44 pm
by volka
somehow the browser has to determine from where it has to pull the image, so no hinding here.
But you might be interested in http://websiteowner.info/tutorials/serv ... htheft.asp

Posted: Mon Feb 17, 2003 3:08 am
by s3rg1o
hrmmm I thought I followed the instructions but I shouldn't be able to do this should I?

http://www.pcgameshots.com/s6.jpg

weird..I cannot get the .htaccess to work even when I try to do authentication...and I have done .htaccess authentication on this server before but now, even when I copy and paste the .htaccess for authentication to another directory to try and get it to work..it won't I know you have to upload in ASCII, which is what I am doing but still no go.. :?

Posted: Mon Feb 17, 2003 8:30 am
by Stoker
perhaps your web host changed the web server settings; In order for local .htaccess settings to work, those settings must be allowed with Allowoverride in the main httpd.conf