Can't display images with php

davecoventry's picture

He has: 112 posts

Joined: Jun 2009

I can't figure why this doesn't work:

<?php
print '<img src="http://example.com/sites/www.webmaster-forums.net/files/pictures/users/u8/thumbs/17082007001.jpg" />';
?>

The file is there the tag seems to be fine when I view the page source, but the picture doesn't display.

Can anyone think of anything?

He has: 629 posts

Joined: May 2007

Silly question - is the image where you say it is?

They have: 121 posts

Joined: Dec 2008

Copy / paste the URL from the produced source.
If the image comes up - weird.
Usually, you'll get a helpful error code - 404 - not found, 403 - Forbidden (file permission error), etc.

Cheers,
Shaggy.

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

If it is a dynamically generated image, double check the headers being sent with it.

-Greg

davecoventry's picture

He has: 112 posts

Joined: Jun 2009

I had the permissions of the directory at drwxrw-rw-

When I changed it to drwxrwxrwx the images appeared.

This is clearly not a good idea. It must be something to do with .htaccess. I'll have to investigate further... Confused

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

On a directory, the "x" part determines if the role can go into it.

So only the owner of the directory could. Most systems, the webserver runs as something other than the owner's account (apache, nobobdy, etc). So with the setting you had, you could have FTP'd in and seen it, but the web server couldn't.

If this is NOT a directory that the webserver needs to write to, then you should do chmod 755 so that only the owner can write, but everyone else can read it and go into it.

-Greg

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.