Kousha
Kousha

Reputation: 36299

Image path not working

I am using Zend, and I have a folder in my /public called /profile/. I store the profile pictures in it. Say there is a file called /test.png inside this. I try to load the picture using

<?php
$path = APPLICATION_PATH . '/../public/profile/test.png';
echo '<img src="' . $path . '" />';
?>

However, nothing loads! I copy the code and paste it in the URL, and this works fine and does show the image! What am I doing wrong here?

Thanks

Upvotes: 0

Views: 989

Answers (2)

Michal M.
Michal M.

Reputation: 1063

It's actually much simpler:

You always need a vhost to make this work. It usually points to folder

your-application/public

If your image is located:

your-application/public/profile/test.png

you then specify image path:

<img src="/profile/test.png" />

There should be no need to employ PHP in this case.

Upvotes: 2

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

APPLICATION_PATH is not HTTP but local filesystem path. You want URL rather than path.

$url = $_SERVER['HTTP_HOST'] . '/profile/test.png';

echo sprintf('<img alt="" src="%s" />', $url);

Upvotes: 0

Related Questions