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
https://forums.phpfreaks.com/topic/257835-help-with-is_file-function/
Share on other sites

When posting code, enclose it within the forum's

 . . . 

BBCode tags.

 

$row['screenshot'] doesn't hold the complete filesystem path to the file, right? is_file needs a complete relative or absolute path to the file.

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.