Page 1 of 1

Genertating a File List SQL compatible

Posted: Mon May 01, 2006 3:36 pm
by a94060
Hi all,

I was wondering if there was a way that i could get the results that come from the reading of directories to the screen put with their location and file size. I then would like to export this and put it into a database that can be searched with all of the file names. I was going to use this code to get all of the file names:

Code: Select all

<?php
foreach (glob("*.mp3") as $filename) {
   echo "$filename size " . filesize($filename) . "\n";
}
?>
(From the php.net site)
I then want to make this into a format that can be imported with phpmyadmin? Has anyone made a class/function or something that can do this or can any suggestions be made? (Would anyone also be able to tell me how to list the location of the file from the root (/) of the drive?

Thanks

Posted: Mon May 01, 2006 4:14 pm
by ambivalent
Instead of outputting it to the browser, write it as a csv file which can be imprted by phpMyAdmin

Code: Select all

$filelist = fopen("dirlist.txt", "w+");

foreach (glob("*.mp3") as $filename) {
  
    fwrite($filelist, $filename.",".filesize($filename)."\n");

}

fclose($filelist);
outputs something like:

Code: Select all

filename.mp3,1055658
filename2.mp3,1748793
...

Posted: Mon May 01, 2006 5:55 pm
by a94060
ambivalent wrote:Instead of outputting it to the browser, write it as a csv file which can be imprted by phpMyAdmin

Code: Select all

$filelist = fopen("dirlist.txt", "w+");

foreach (glob("*.mp3") as $filename) {
  
    fwrite($filelist, $filename.",".filesize($filename)."\n");

}

fclose($filelist);
outputs something like:

Code: Select all

filename.mp3,1055658
filename2.mp3,1748793
...
is there anyway i can make php read things from the id tags on mp3 files? i want to add like the artist and the song name also if possible.

Posted: Mon May 01, 2006 5:58 pm
by feyd
search through the forum for ID3, we've talked about how to retrieve the tags before.

Posted: Wed May 03, 2006 12:33 pm
by a94060
i found what i wanted to do and it is now in the database,thanks.