I need to be able to put a quick check to see if an image with a particular name exists in a particular location... It's possible, isn't it?

    $imagelocation = '/home/images/image.jpg';
    if (file_exists($imagelocation)) {
    echo 'image ok';
    }

      zzz wrote:

      I need to be able to put a quick check
      to see if an image with a particular name exists in a particular location...
      It's possible, isn't it?

      If you have path to any file, not just images,
      you can check if this FILE IS there .... or not:

      Read more:
      [man]is_file/man

      <?php
      
      $path = './images/logo.gif';
      
      if( is_file($path) )
      {
          echo 'yes, it is';
      }
      else
      {
          echo 'no, it isnt';
      }
      
      ?>

      we also have:

      [man]is_dir/man

      .... and:

      is_ dir

      is_ executable

      is_ file

      is_ link

      is_ readable

      is uploaded file

      is_ writable

      regars 🙂
      halojoy

        21 days later

        I am also trying to do something similar to this, but I am having some difficulty with it. I think this is because I am trying to check to see if a file exists, but the actual file that I am checking will vary based on what page is being pulled up. For example, I am trying to display a player image on a page. This player image depends on the player's name and if there is no photo, it will display a generic image. So this is what I have...

        $playername = $row['name'];
        $playerpic = '/poker/images/players/$playername.gif';
        	if( is_file($playerpic) ){
        		echo "<table width=\"400\" border=\"0\">";
        		echo "<tr><td rowspan=\"3\"><center><img src=\"http://www.mysite.net/poker/images/players/$playername.gif\"><br/> <strong><FONT SIZE=\"5\">$playername</FONT></strong><br/></td></tr>";
        			echo "</table>";
        			echo "<br/>";
        		}

        However, it is always reverting to the else statement photo. I know the files are uploaded and that is the correct location, it has to be the $playername.gif part of the code that is giving me the issue. What is another way to accomplish this? Thanks!

          Try...

          $playerpic = '/poker/images/players/'.$playername.'.gif';
          
            shmoo525 wrote:

            Try...

            $playerpic = '/poker/images/players/'.$playername.'.gif';
            

            Just tried it out, but no luck. 😕

              I have messed with different variations of this line of code, using is_link, file_exists, is_file, etc and no luck. Is there another way to call the $playername? That seems to be my issue.

              If I replace my else statement with $playername.gif instead of chippics.gif it shows the correct image. The problem is when I don't have an image for the playername, I want to show the chippics.gif image.

              I have looked all over for answer to this, but I am not finding any help in regards to calling a file that is dependent on the page you are currently on.

                Write a Reply...