Ste
Ste

Reputation: 1520

php image jpg header problem

HI, i have an image .jpg into my server. If I link direct to image i have this error:

Forbidden You don't have permission to access http://...

I need to show with php. I have try


header('Content-Type: image/jpeg');
readfile('$file');

But nothing... I have also try using server root... any suggestions?

Upvotes: 0

Views: 1799

Answers (4)

tloach
tloach

Reputation: 8040

Probably the file is in a directory that the web server isn't set up to allow access to. PHP can access pretty much any directory on the web server, but apache/IIS/etc will restrict normal access by default to only directories specified in their configuration. If this is the problem then serverfault may have better expertise to help you get your server set up.

Upvotes: 0

Mark Baker
Mark Baker

Reputation: 212412

'$file'

in single quotes is looking for a file called $file

"$file"

in double quotes or even without any quotes at all, is looking for a file called by the value stored in $file

Upvotes: 1

Álvaro González
Álvaro González

Reputation: 146390

You are trying to load a file called $file. That's a weird name for a picture; I assume it's a PHP variable name where you store the picture file name. In such case:

header('Content-Type: image/jpeg');
readfile($file);
exit;

Upvotes: 3

Flo
Flo

Reputation: 1671

You have to set the correct rights for the image. You can do this via ssh (console) or easier with your ftp program. If done so, you can access it directly

Upvotes: 0

Related Questions