Loading ...
Sorry, an error occurred while loading the content.

"file_exists" Problem in wordpress

Expand Messages
  • Bijon
    i am using to Know file existing, but it is Not Working
    Message 1 of 3 , Apr 19, 2012
    • 0 Attachment
      i am using to Know file existing, but it is Not Working

      <?php
      //echo get_the_ID();
      $imagepath=get_bloginfo('template_directory')."/singelpage/".get_the_ID().".jpg";

      if(file_exists($imagepath))
      {
      ?>
      <div id="singelpagehimage" title="<?=$post->ID?>" >
      <img src="<?php echo $imagepath; ?>" alt="<?php the_title();?>"/>
      </div>

      <?php } else { echo "File Not Exist"; }?>

      Any Can Help ME??
    • Tareq Hasan
      The image path you are generating is a url to the image, not the file path. So you can t check the existence of a url with file_exists() function. Instead of
      Message 2 of 3 , Apr 19, 2012
      • 0 Attachment
        The image path you are generating is a url to the image, not the file path. So you can't check the existence of a url with file_exists() function.

        Instead of using get_bloginfo('template_directory'), use TEMPLATEPATH constant
        --------------------------------------------
        Best regards
        Tareq Hasan
        Blog | Twitter

      • Bijon
        Finaly its done, thanks to all. and my coding...
        Message 3 of 3 , Apr 21, 2012
        • 0 Attachment
          Finaly its done, thanks to all. and my coding...

          <?php
          $pid=get_the_ID();
          $imagepaths=get_bloginfo('template_directory')."/singelpage/".$pid.".jpg";
          $imagepath=TEMPLATEPATH."/singelpage/".get_the_ID().".jpg";
          if(file_exists($imagepath))
          { ?>
          <div id="singelpagehimage" title="<?=$post->ID?>" >
          <img src="<?php echo $imagepaths; ?>" alt="<?php the_title();?>"/>
          </div>
          <?php } ?>
        Your message has been successfully submitted and would be delivered to recipients shortly.