<?php
include 'config.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>File scanner - movies</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
$medialocations = explode("|", MOVIELOCATIONS);
//recurse many different file storage locations
$j=0;
while ($j < count ($medialocations)) {
$files = listdir($medialocations[$j]);
// recurse directories within those locations
$i=0;
while($i < count($files)) {
// split $files into path and file name strings
$filename = basename($files[$i]);
$pathname = dirname($files[$i]);
$i++;
$extension = getExtension($filename);
// only add files of accepted extensions (config.php)
if (in_array($extension, $scan_add_extensions))
{
// check the script isn't attempting to insert duplicate. We assume that filename and path are indexed, else this might take longer. If so, I might need to find a more elegant way of doing this.
mysql_query("select id from movie_scanresults where filename = '".addslashes($filename)."' and path = '".addslashes($pathname)."' limit 0,1");
if (mysql_affected_rows() == 0)
{
// This record is not a duplicate, so insert to the database
mysql_query("insert into movie_scanresults (filename,path) values ('".addslashes($filename)."','".addslashes($pathname)."')");
};
// echo "file:".$filename." ---- ";
// echo "path:".$pathname."<br />";
};
};
$j++;
};
?>
<h1>Scan complete</h1>
</body>
</html>