cameronjonesweb
cameronjonesweb

Reputation: 2506

Getting an image if it exists with variable file name

Pretty much explains itself. If I just just get the image to load with this:

<img src="/dm cricket/admin/img/tables/<?php htmlout($name);?>_2.jpg">

it works, but if I decide to change the code to this:

<?php if(file_exists('/dm cricket/admin/img/tables/'.$name.'_2.jpg')){
    ?>
<img src="/dm cricket/admin/img/tables/<?php htmlout($name);?>_2.jpg"><?php }
else {
    echo 'No competition held';}?>

it doesn't work, it only echoes 'No competition held'. Can anyone explain why?

Upvotes: 0

Views: 89

Answers (1)

Quentin
Quentin

Reputation: 943480

A root relative URI from the URI of the page as fetched over HTTP is not going to be the same thing as a file path on the file system of the web server.

Assuming a simple configuration of the server, you would have to prefix the file path with the path to the server's web root directory.

Upvotes: 1

Related Questions