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
Post
by s3rg1o » Sun Feb 16, 2003 4:58 pm
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??
Stoker
Forum Regular
Posts: 782 Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:
Post
by Stoker » Sun Feb 16, 2003 5:17 pm
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 » Sun Feb 16, 2003 6:28 pm
ok so what else do I have to add so that it will output the file?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Feb 16, 2003 7:42 pm
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');
?>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Feb 16, 2003 8:36 pm
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 » Sun Feb 16, 2003 8:56 pm
yes! THANK YOU VOLKA!
s3rg1o
Forum Commoner
Posts: 32 Joined: Sun Feb 16, 2003 4:58 pm
Post
by s3rg1o » Sun Feb 16, 2003 8:59 pm
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
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Feb 16, 2003 9:19 pm
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 » Sun Feb 16, 2003 9:34 pm
so essentially your saying I am screwed in that aspect
Stoker
Forum Regular
Posts: 782 Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:
Post
by Stoker » Sun Feb 16, 2003 9:58 pm
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 » Sun Feb 16, 2003 10:18 pm
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
s3rg1o
Forum Commoner
Posts: 32 Joined: Sun Feb 16, 2003 4:58 pm
Post
by s3rg1o » Mon Feb 17, 2003 3:08 am
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..
Stoker
Forum Regular
Posts: 782 Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:
Post
by Stoker » Mon Feb 17, 2003 8:30 am
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