Jump to content

[SOLVED] Checking file existence through a list of file locations gathered from an array


BhA

Recommended Posts

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

 

 

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?

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?

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.

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.