Jump to content

help with "is_file" function


dryving

Recommended Posts

I'm getting back into web coding after 5 years and am re-learning PHP & Mysql.  I am using a book of tutorials and am having a problem with this section of code. The problem is that the "is_file" test always fails.  If I remove the test then the image files (whose name we're pulling from the database) display as intended.  The constant "GW_UPLOADPATH" is correct as it correctly displays the default image when the "is_file" test fails. I'm sure it's something simple I'm just overlooking.  Thanks for the help

 

<?php
     //Define the upload path and maximum file size constants
   define('GW_UPLOADPATH', 'images/');
  // Connect to the database 
  $dbc = mysqli_connect('localhost', 'testing', '12345', 'guitarwars');

  // Retrieve the score data from MySQL
  $query = "SELECT * FROM guitarwars";
  $data = mysqli_query($dbc, $query);

  // Loop through the array of score data, formatting it as HTML 
  echo '<table>';
  while ($row = mysqli_fetch_array($data)) { 
    // Display the score data
    echo '<tr><td class="scoreinfo">';
    echo '<span class="score">' . $row['score'] . '</span><br />';
    echo '<strong>Name:</strong> ' . $row['name'] . '<br />';
    echo '<strong>Date:</strong> ' . $row['date'] . '</td>';
   if (is_file($row['screenshot']) && filesize($row['screenshot']) > 0) {
   echo '<td><img src="' . GW_UPLOADPATH . $row['screenshot'] . '" alt="Score Image" /></td></tr>';
   }
   else {
    echo '<td><img src="' . GW_UPLOADPATH . 'unverified.gif" alt="Unverified Score" /></td></tr>';
   }
  }
  echo '</table>';

  mysqli_close($dbc);
?>

 

MOD EDIT:

 . . . 

BBCode tags added.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.