header problem (content-disposition)

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

s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

header problem (content-disposition)

Post 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??
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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)
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post by s3rg1o »

ok so what else do I have to add so that it will output the file?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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');
?>
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

do not put it into the attachment ;)

Code: Select all

<?php
header('Content-type: image/jpeg');
readfile('/home/me/images/logo02.jpg');
?>
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post by s3rg1o »

yes! THANK YOU VOLKA! :D
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

right, the html is one document and the image is one document.
Only one document per request. Not a limitation of php.
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post by s3rg1o »

so essentially your saying I am screwed in that aspect
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

It's the nature of HTML, you link to images with <img> tags, they are never stored in the same file...
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
s3rg1o
Forum Commoner
Posts: 32
Joined: Sun Feb 16, 2003 4:58 pm

Post 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.. :?
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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
Post Reply