Smudly Posted October 22, 2010 Share Posted October 22, 2010 When I upload new files, their file name is stored into my database. I have been told that a couple of the file downloads weren't working. Upon further investigation I figured out that the file the person wanted to download was nowhere to be seen in my downloads directory. How can I determine if a file exists in my directory? I assume I can somehow use the location that is stored inside my database (ex: myfile.pdf) and compare that with what's in the folder. Quote Link to comment https://forums.phpfreaks.com/topic/216520-how-to-determine-if-a-file-is-missing-from-my-server/ Share on other sites More sharing options...
DavidAM Posted October 22, 2010 Share Posted October 22, 2010 the file_exists() function will check to see if a file exists. Quote Link to comment https://forums.phpfreaks.com/topic/216520-how-to-determine-if-a-file-is-missing-from-my-server/#findComment-1125051 Share on other sites More sharing options...
Smudly Posted October 22, 2010 Author Share Posted October 22, 2010 Thanks for the reply. I tried using file exist to check each row in the table and determine if the file does in fact exist. If it does not, that row will be displayed to the page. If it does exist, nothing will be done. The problem I am having is it is displaying ALL rows to the page. I've tried changing up the code in various ways but nothing seems to work. Here is my code. (no errors are displayed either) $result = mysql_query("SELECT * FROM sheets WHERE active='yes'"); $path = "/uploads/"; echo "<table border='0' cellspacing='0' cellpadding='0'>"; echo "<th>ID</th> <th>Artist</th> <th>Title</th> <th>URL</th> "; $i = 1; while($row = mysql_fetch_array($result)){ $url = $row['url']; $sheet = $path.$url; if (file_exists($sheet)){ $artist = ""; $title = ""; $sheet = ""; } else{ $artist = $row['artist']; $title = $row['title']; echo "<tr>"; echo "<td>$i</td>"; echo "<td>$artist</td>"; echo "<td>$title</td>"; echo "<td>$url</td>"; echo "</tr>"; $i++; } } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/216520-how-to-determine-if-a-file-is-missing-from-my-server/#findComment-1125055 Share on other sites More sharing options...
DavidAM Posted October 22, 2010 Share Posted October 22, 2010 Since file_exists() is a PHP function, it needs the real path to the file; not the path relative to your document root. If that uploads directory is in your document root, you can change that to: $path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/"; $sheet = $path.$url; if (file_exists($sheet)){ Quote Link to comment https://forums.phpfreaks.com/topic/216520-how-to-determine-if-a-file-is-missing-from-my-server/#findComment-1125062 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.