Re: Read directory; store filenames found in mySQL table? :: SOLVED!!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Thanks All (Especially Warren); Final Code:

function dirList ($directory) {
   $results = array();
   $handler = opendir($directory);
   while ($file = readdir($handler)) {
       if ($file != '.' && $file != '..')
           $results[] = $file;
   }
   closedir($handler);
   return $results;
}

$origin = "pathto/images/";

#load file listing into an array
$shell = shell_exec("du $origin");
$array  = array_reverse(explode("\n",$shell));
$contIdArr = array();

$newArr = array();
foreach($array as $elem){
   $newDir = "";
   $pathArray = explode("/", $elem);
   $nodeDepth = count($pathArray);
   for($count=1; $count<$nodeDepth; $count++){
       $newDir = $newDir.$pathArray[$count].'/';
   }
   $newArr[] = '/'.$newDir;
}
sort($newArr);

foreach($newArr as $dir){
   $pathArray = explode("/", $dir);
   $fileListArr = dirList($dir);
}

	$db = mysql_connect("localhost","usr","pwd");
	mysql_select_db("db",$db);
	
	foreach($fileListArr AS $value) {
		$sql="INSERT INTO r2 (ID, RECORDING) VALUES('','$value')";
		$result = mysql_query($sql) or die (mysql_error());
	}
	

---
Rahul Sitaram Johari
Founder, Internet Architects Group, Inc.

[Email]	sleepwalker@xxxxxxxxxxxxxxxx
[Web]	http://www.rahulsjohari.com





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux