Problem to show file

Hi,
I go to the following link highlighted, within CentOS 6.5
5while the file is having this
<img src="<?php echo '/home/huamin/Downloads/emu_wild_animal_bird.jpg'; ?>" alt="picture description here">

inside. but why can't I show the jpg file on the web-page, while it does exist within the folder.
LVL 11
HuaMin ChenProblem resolverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Probably because /home/huamin is not part of the URL path to the image.  Try using getcwd() to discover the current working directory.  This will tell you the server path.  Then compare the server path to the URL path as shown in the documentation on the man page.  My guess is that the relative URL Downloads/emu_wild_animal_bird.jpg would work, but that is only a guess -- you'll have to experiment to get the complete and correct URL.
0
skijCommented:
First, view the page source that is being served.
Paste this into your browser:
view-source:http://127.0.0.1/info3.php

Open in new window

Check to make sure that the link is:
<img src="/home/huamin/Downloads/emu_wild_animal_bird.jpg" alt="picture description here">

and not:
<img src="<?php echo '/home/huamin/Downloads/emu_wild_animal_bird.jpg'; ?>" alt="picture description here">

If the link is:
http://127.0.0.1/home/huamin/Downloads/emu_wild_animal_bird.jpg

then make sure that there is an image in that location.
0
HuaMin ChenProblem resolverAuthor Commented:
Skij
I adjust the info3.php file to have

<img src="/home/huamin/Downloads/emu_wild_animal_bird.jpg" alt="picture description here">

but I still get this
6
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Julian HansenCommented:
Because
/home/huamin/Downloads
Is not relative to the webroot It looks like it is in your home folder
You normally have a structure like this (or similar)
/var
   /www
     /yoursite
         /public-html
              <html pages can only request files in this folder and in sub-folders of this folder>
/home
   /huamin
      /Downloads
           <files here are not accessible through an HTTP request as they are outside of the web root>

Open in new window

You need to do something like this

/var
   /www
     /yoursite
         /public-html
            /Downloads
                emu_wild_animal_bird.jpg

Open in new window

And then change your img src to
<img src="Downloads/emu_wild_animal_bird.jpg" alt="..." />

Open in new window

0
HuaMin ChenProblem resolverAuthor Commented:
Hi,
My PHP file does exist within

/var/www/html/

does it mean I should create folder

public-html

within this

/var/www/html/

?
0
Julian HansenCommented:
No, as I said that was a sample structure - yours should be similar but does not have to be exact

If you have
   /var
      /www
         /html

Open in new window

Then you need to put your .JPG somewhere in the html folder OR A folder below it for example
   /var
      /www
         /html
             /images
                  emu_wild_animal_bird.jpg

Open in new window

And your img would then be
<img src="images/emu_wild_animal_bird.jpg" alt="..." />

Open in new window

1
skijCommented:
Here is some "over the top" code to help you tourbleshoot.  It will try to find the image.  
<?php

$base = '/var/www/html/';
$img = rglob($base . '*emu_wild_animal_bird.jpg');

if(empty($img)) echo 'Image Not Found';
else echo '<img src="'. str_ireplace('%2F', '/', str_ireplace(rtrim($base,'\\'),'',$img[0])) .'" alt="Image Not Found" />';

function rglob($pattern, $flags = 0) {
    $files = glob($pattern, $flags); 
    foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
        if(empty($files[0])) $files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
    }
    return $files;
}
?>

Open in new window

0
HuaMin ChenProblem resolverAuthor Commented:
Many thanks all.
Julian,
BTW, one last thing, how to control the size there, to the image shown?
0
Julian HansenCommented:
That is controlled through CSS or inline styling (CSS is preferred)

CSS
img.someclass {
   width: = 100px;
}

Open in new window

HTML
<img class="someclass" src="images/emu_wild_animal_bird.jpg" />

Open in new window

To maintain aspect ratio set the width or the height the other will adjust automatically. You can set both but it is unnecessary and not responsive.
An even better solution is to put the image in a container and style the container - you then make the image width 100% - it will always fit the container - so if the size of the container is variable (like in a responsive design) the image will auto size to fit the container.
0
HuaMin ChenProblem resolverAuthor Commented:
Many thanks Julian.

I'm not able to decrease the length of the picture file after having put these

img.class1 {
   width: = 100px;
}

<img class="class1" src="images/emu_wild_animal_bird.jpg" alt="picture description here">

Open in new window

into the PHP file.
0
Julian HansenCommented:
Apologies - my previous post had a typo - the '=' sign should not be there.
It should be this
img.class1 {
   width: 100px;
}

Open in new window

0
HuaMin ChenProblem resolverAuthor Commented:
Here is what inside the PHP file
img.class1 {
   width: 100px;
}

<img class="class1" src="images/emu_wild_animal_bird.jpg" alt="picture description here">

but I only get the following
7b
0
Julian HansenCommented:
This is drifting away from the original question - take a look at the response below and if that does not work for you please consider opening another question as the original question was about how to reference the file in the file system.

Did you put your CSS inside a <style> tag or CSS file?
<!doctype html>
<head>
<style type="text/css">
img.class1 {
   width: 100px;
}
</style>
</head>
<body>
<img class="class1" src="images/emu_wild_animal_bird.jpg" alt="picture description here">
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.