Jump to content

basic PHP help... ultimate beginner


ufbobbo

Recommended Posts

Hi there,

 

I just started using PHP tonight and I'm trying to figure out a basic if then else statement using file_exists to check if an image file exists on the server.  If it exists, I'd like to display it otherwise I would like to display a generic image.  Any help as to why I'm getting errors in the code?

 

<?php if (file_exists("../../<?php $key="applogo"; echo get_post_meta($post->ID, $key, true); ?>.png"))  { ?>

<img src="../../wp-content/gallery/app_logos/genericlogo.png" width="50" height="50">

<?php } else { ?> 

<img src="../../wp-content/gallery/app_logos/<?php $key="applogo"; echo get_post_meta($post->ID, $key, true); ?>.png" width="50" height="50">

<?php endif; ?>

 

Thank you kindly for any help you could give!

Link to comment
https://forums.phpfreaks.com/topic/194309-basic-php-help-ultimate-beginner/
Share on other sites

Teamatomic,

 

Thank you for your help, but I am still getting an error when I try to implement it this way (sorry, I am very new to programming so thank you for your patience):

 

<?php
    $key="applogo"
    $appname=get_post_meta($post->ID, $key, true);
    echo $appname;
    $appfilename="http://www.websitename.com/wp-content/gallery/app_logos/$appname";
    echo $appfilename;
      if(file_exists("$appfilename"))
      {
        echo '<img src="http://www.websitename.com/wp-content/gallery/app_logos/$appname" width="100" height="100">';
      }
      else
      {
        echo '<img src="http://www.websitename.com/wp-content/gallery/app_logos/genericlogo.png" width="100" height="100">';
      }
   ?>

 

Parse error: syntax error, unexpected T_VARIABLE

Ahhh.. finally figured it out (I'm slow  :confused:).  Thank you for the guidance!

 

  <?php
    $key="applogo";
    $appname=get_post_meta($post->ID, $key, true);
    $appfilename="actual_server_path_NOT_website_path/$appname.png";
      if(file_exists("$appfilename"))
      {
      echo '<img src="http://www.websitename.com/wp-content/gallery/app_logos/'.$appname.'.png" width="100" height="100">';
      }
      else
      {
        echo '<img src="http://www.websitename.com/wp-content/gallery/app_logos/genericlogo.png" width="100" height="100">';
      }
   ?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.