BhA Posted June 8, 2007 Share Posted June 8, 2007 Hi guys, I've been trying to wrote a code to check the existence of some files gathered from a field in mySql database. And I am kind a stuck at a point where I get the file locations from the database but when it passes those locations to file exist it keeps telling me the file does not exist. Only first file exists the other 2 file does not exist to test if the code was working or not. <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $db = mysql_connect("dbaddress","username","pass"); if ( $db != FALSE) { print "connected to the database"; } else { print "connection failed to the database"; } mysql_select_db("dbname", $db); $result = mysql_query("SELECT resume FROM `test`", $db); while ($row = mysql_fetch_array($result)) { printf ("Link: %s", $row[0]); $filename = $row[0]; if (file_exists($filename)) { echo "The file $filename exists."; } else { echo "The file $filename does not exist."; } } ?> </body> </html> you can check the result at www.flxdesign-prototype.com/testdb.php I would appreciate any help or guidance. Thanks, BhA Link to comment https://forums.phpfreaks.com/topic/54817-solved-checking-file-existence-through-a-list-of-file-locations-gathered-from-an-array/ Share on other sites More sharing options...
soycharliente Posted June 8, 2007 Share Posted June 8, 2007 From the API on the function, I gather that it checks the entire path provided. If you just supply a filename, it seems like it would check the root directory. Make sure you're giving teh full path. Could that be it? Link to comment https://forums.phpfreaks.com/topic/54817-solved-checking-file-existence-through-a-list-of-file-locations-gathered-from-an-array/#findComment-271134 Share on other sites More sharing options...
BhA Posted June 8, 2007 Author Share Posted June 8, 2007 Thanks charlieholder, But it's not it sql field already contains the full path of the files. You can see it from the http://www.flxdesign-prototype.com/testdb.php too. Link to comment https://forums.phpfreaks.com/topic/54817-solved-checking-file-existence-through-a-list-of-file-locations-gathered-from-an-array/#findComment-271150 Share on other sites More sharing options...
BhA Posted June 11, 2007 Author Share Posted June 11, 2007 Well I really appreciate som here I still couln't figure out the problem. Link to comment https://forums.phpfreaks.com/topic/54817-solved-checking-file-existence-through-a-list-of-file-locations-gathered-from-an-array/#findComment-272167 Share on other sites More sharing options...
soycharliente Posted June 11, 2007 Share Posted June 11, 2007 Why are you using $row[0]? Shouldn't you be using the field name to reference? Wouldn't 0 just give you the first file in the array every time? Link to comment https://forums.phpfreaks.com/topic/54817-solved-checking-file-existence-through-a-list-of-file-locations-gathered-from-an-array/#findComment-272260 Share on other sites More sharing options...
BhA Posted June 11, 2007 Author Share Posted June 11, 2007 Well I don't think thats the problem, if you check the result page you can see that it increments the value $row[0] and it fetches the right links. I was wondering whether the file permissions are causing the problem or not. Any ideas? Link to comment https://forums.phpfreaks.com/topic/54817-solved-checking-file-existence-through-a-list-of-file-locations-gathered-from-an-array/#findComment-272272 Share on other sites More sharing options...
trq Posted June 11, 2007 Share Posted June 11, 2007 The problem is more likely caused by url wrappers not being enbled. Use valid file paths, not urls. Link to comment https://forums.phpfreaks.com/topic/54817-solved-checking-file-existence-through-a-list-of-file-locations-gathered-from-an-array/#findComment-272288 Share on other sites More sharing options...
BhA Posted June 11, 2007 Author Share Posted June 11, 2007 Thanks Charlieholder & Thorpe, It's working now probably charlie mentioned the same thing that you said Thorpe at his first post but I didn't get it until you said "not the url". Well anyways thank you guys this was giving me lots of trouble. Link to comment https://forums.phpfreaks.com/topic/54817-solved-checking-file-existence-through-a-list-of-file-locations-gathered-from-an-array/#findComment-272303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.