 |
 |
PHP - MySQL cataloging question
|
 |
|
 |
|
Forum Regular
Join Date: Jul 2002
Location: Seattle
Status:
Offline
|
|
I'm still a newbie to PHP and MySQL and so I may not know exactly what I'm trying to ask. I haven't gotten much farther than the generic "hello world" tutorials, but I do have JavaScript and ASP experience and am generally familiar with Object Orianted Programming.
I was wondering if there was a way to create a PHP script in an HTML page, drop said page in my top level mp3 folder, and that script would search all the subdirectories and catalog all my mp3's and enter it into a MySQL database. When I add new mp3's or delete ones I don't want, and then run the script again, it would automatically update the database. Of course, an HTML output listing all my mp3's by genre, band, or whatever would be necessary as well.
This would be a very cool way to catalog all my pictures too (maybe even with thumbnails???).
thanks in advance for any help,
Chris
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: England
Status:
Offline
|
|
Try this:
Make an Applescript to add items to a text file for each picture. Set it to a folder action. Have it call your script as the last thing it does.
The PHP script should then parse the text file and add that to the database. It should then empty the text file (so only the changes are added each pass of the script)
You should have a full 'refresh' Applescript/PHP combo that runs every month or so, in case any errors creep in.
If you want help with the PHP, reply here.
Amorya
|
|
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Dec 2001
Location: Sweden
Status:
Offline
|
|
You should be able to do this in PHP. I haven't done anything like it but I guess you could:
1. Create a function that takes a directory as input.
2. Call this function to traverse a directory looking for mp3's. If it finds one. Store it in the database. If the file already exists in the database, modify it's date field and set it to the date your update takes place.
3. If it finds another directory within itself, have the function call itself passing the found directory. The function should now loop with every directory it finds. Returning to itself and continuing where it left until it returns to the main caller.
4. Delete every record that hasn't the latest date.
Ok. this is just a rough sketch, but I think it should work. It even sounds like something I would like to try to do.
//megus
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Dec 2001
Location: Sweden
Status:
Offline
|
|
Ok. Back again...
Here's a PHP-script to get you started.
This script takes a directory path as it's input and traverse every directory in this path.
Please note that the webserver must have readaccess to the directory.
[php]
<?php
function traverseDirectory($path)
{
//open the directory
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "Directory Listing of $path<br>";
//loop through the directory
while ($file = readdir($dir_handle)) {
if(substr($file,0,1)==".") continue; //if the file is invisible; continue
if (is_dir($path.$file)) {
//if the found file is a directory. loop with this.
traverseDirectory($path.$file."/");
} else {
//else just echo the file's name.
echo "$file<br>";
}
}
//close the directory
closedir($dir_handle);
return;
}
//exchange the myHomeDir wih your short name.
traverseDirectory("/Users/myHomeDir/Sites/");
?>
[/php]
It's getting late and I'm off to bed.
Hope this script will help you get you started.
//megus
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jul 2002
Location: Seattle
Status:
Offline
|
|
Thanks Amorya and megus.
Wow, I almost forgot about this. I'm so tied up on a for-pay project that this for-fun project had slipped my mind.
I just bought the O'Reilly book "Programming PHP" because I heard it was one of the best but I couldn't find anything about traversing directories. It seems like a simple enough function though.
I'll give it a shot this weekend. Thanks again,
Chris
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Sep 2000
Location: Shallow Alto, CA
Status:
Offline
|
|
Just ran across this script that might help you out.
PHPWizard.net
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|