Genertating a File List SQL compatible

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Genertating a File List SQL compatible

Post 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
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post 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
...
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

search through the forum for ID3, we've talked about how to retrieve the tags before.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

i found what i wanted to do and it is now in the database,thanks.
Post Reply