Hi all,

am a web developer with average PHP skills and I need some help for you guys.

I have a table online that has data and a link in one of he columns: i.e. after a reader performs a search, he has the option to download a file. Files are in folders and there is the root folder. The document links in the db is relative. i.e. folder1/folder/123.pdf etc

What am looking for is a script or info how to check the database for missing documents. i.e. to compare the information in the database and actual files in the folders.

Thanks in advance

Recommended Answers

All 8 Replies

Something like this should work

<?
$query = //query
$result = mysql_query($query);
$total = mysql_num_rows($result);

for($i = 0; $i < $total; $i++)
{
	if(!file_exists($_SERVER['DOCUMENT_ROOT'] . mysql_result($result, $i, "filename"))
	{
		echo mysql_result($result, $i, "filename") . " does not exist<br />";
	}
}
?>

I have modified as follows but doesnt work: it gives me an error

<?php 
mysql_select_db($database_connNew, $connNew);
$query_case_link = "SELECT cas1, casLink, cas2 FROM tbl";
$case_link = mysql_query($query_case_link, $connNewEklr) or die(mysql_error());
$row_case_link = mysql_fetch_assoc($case_link);
$totalRows_case_link = mysql_num_rows($case_link);

$filename="../123/".$row_case_link['casLink'];

$result = mysql_query($query_case_link);
$total = mysql_num_rows($case_link);

for($i = 0; $i < $total; $i++)
{
	if(!file_exists($_SERVER['DOCUMENT_ROOT'] . mysql_result($result, $i, $filename))
	{
	
		echo mysql_result($result, $i, "filename") . " does not exist<br />";
	}
else 
{
echo 	mysql_result($result, $i, "filename") . " hiyo iko<br />";
	}
}
mysql_free_result($case_link);
?>

Hi,

Can you post the error?

I got the code working and it performs like charm on my localhost.

here is the code:

<?php 
mysql_select_db($database_connNew, $connNew);
$query_case_link = "SELECT cas1, casLink, cas2 FROM tbl";
$case_link = mysql_query($query_case_link, $connNew) or die(mysql_error());
$row_case_link = mysql_fetch_assoc($case_link);
$totalRows_case_link = mysql_num_rows($case_link);

$result = mysql_query($query_case_link);
$total = mysql_num_rows($case_link);

do
	{
	
	$filename="folder/".$row_case_link['casLink'];
	$filename = $_SERVER['DOCUMENT_ROOT'] ."/". $filename;
	$filename = str_replace('/','\\',$filename);
	
	echo $filename;
	exit();

	if(!file_exists($filename))
		{	
		echo $filename . " does not exist<br />";
		}
	else 
		{
		echo 	$filename . " hiyo iko<br />";
		}
	} while ($row_case_link = mysql_fetch_assoc($case_link)); 		
exit();

//echo(mysql_result($result, 1, $filename));
//exit();

mysql_free_result($case_link);
?>

that is all well until I put the code online.

my online host uses linux but my localhost is on wampserver. Different worlds. If you have any ideas how to configure root on plesk please post them here. If I can do it alone; I will be telling you

Are you getting an error?

I dont get an error but cant place my directory structure.

I have: \var\www\vhosts\website.org\httpdocs\folder\document.php

Tells me that all files are missing but I guess its because I cant get the directory structure right

I would assume so, just echo the dir structure that your script is looking in so that you can see what is wrong with it.

I have echoed the dir structure and that is were I get the /var/ . . . etc as in my previous email.

what I need is to locate the path to my root and I will be able to navigate my way from there. AM also raising this issue with my hosts

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.