dryving Posted February 26, 2012 Share Posted February 26, 2012 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 More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 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. Link to comment https://forums.phpfreaks.com/topic/257835-help-with-is_file-function/#findComment-1321511 Share on other sites More sharing options...
dryving Posted February 26, 2012 Author Share Posted February 26, 2012 Thank you. I knew it was something simple. I forgot to add the constant. Sorry about the code. I tried to look at the rules to know how to paste code but for some reason it would not open when clicked. Link to comment https://forums.phpfreaks.com/topic/257835-help-with-is_file-function/#findComment-1321536 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.