The following code reads all the files in a specific folder and inserts the directory name and extension into the database.
$directory = "C:\Documents and Settings\Jeffrey Klassen\My Documents\my music\Fall Out Boy";
if ($handle = opendir($directory))
{
echo "Files:\n<BR>";
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle)))
{
if(eregi("(\.(mp3)|(wma))$", $file))
{
echo $file;
$query = "INSERT INTO files (extension, dir) VALUES (\"$file\", \"$directory\")";
$result = mysql_query($query) or die(mysql_error());
}
}
closedir($handle);
}
The problem is that the directory name gets read as:
C😃ocuments and SettingsJeffrey KlassenMy Documentsmy musicFall Out Boy
note: this is with out the necessary "\". Im sure this is a dumb question, but how do i include the "\" when inserting into database?