|
-
Feb 15th, 2006, 03:59 PM
#1
Thread Starter
Frenzied Member
How to output part of feild using mysql and php
Hi all. i got a huge list of mp3 that they are in diffrent folders. I put all the songs infor in mysql database in a table called files. I want a query db that output foldernames for me .The folder name is part of feiled called filename in files table. The value of filename is like this stored in db :
http://localhost/wimpy5recursive/mp3s/album1/song1.mp3
http://localhost/wimpy5recursive/mp3s/album2/song4.mp3
where the bold part is the foldername. i want to print folder name.Note:mp3s is the root folder for mp3s.The whole point is to list all folders name and link to page that holds songs inside those folders.
Furthermore, i want a query all feilds info for songs in each given folder.What i mean is that for each folder it lists all songs info iside that folder.I want to be able to tell the query what folder i want to list its song.Thanks
-
Feb 15th, 2006, 06:45 PM
#2
Hyperactive Member
Re: How to output part of feild using mysql and php
we arent gunna do it for you.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Feb 18th, 2006, 10:34 PM
#3
Member
Re: How to output part of feild using mysql and php
Not sure what your looking for... heres somthing i used to display mp3s from a Dir i would pass via url.com?folder=foldername
PHP Code:
if ($handle = opendir($_GET['folder'])) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (preg_match('#^(.+).mp3$#', $file, $match)){
$files[] = $file;
} else {
$dirs[] = $file;
}
}
}
closedir($handle);
if (count($dirs) != 0) {
sort($dirs);
//echo "".$dirs[];
}
if (count($files) != 0) {
sort($files);
}
}
echo "Sub Folders<hr align='left' width='74%'>" ;
for ($i = 0; $i < count($dirs); $i++) {
echo "<a href='?folder=".$_GET['folder']."/".$dirs[$i]."'>".$dirs[$i]."</a><br />" ;
}
echo "<h2><hr align='left' width='52%'>".$_GET['folder']." (".count($files).")<hr align='left' width='52%'></h2>";
for ($i = 0; $i < count($files); $i++) {
$date = date("M j Y",filectime($_GET['folder']."/".$files[$i])) ;
$size = formatsize(filesize($_GET['folder']."/".$files[$i])) ;
echo $date." <a href='".$_GET['folder']."/".$files[$i]."'>".$files[$i]."</a> - ".$size."<br />" ;
}
-
Feb 26th, 2006, 12:00 PM
#4
Member
Re: How to output part of feild using mysql and php
AGREE WITH PlaGuE!
NEXT TIME U HAVE A PROBLEM LIKE THIS U´LL LOSE LESS TIME THINKING.
IT CAN BE MADE BY THE MYSQL SERVER WHITH FUNCTIONS OR DOIT YOUR SELF IN CODE.
Last edited by juanmf; Mar 4th, 2006 at 05:10 PM.
If an answer to your question has been helpful, then please, Rate it! where are u?
On Staying Informed and Intellectual Self-Defense
There's no way to be informed without devoting effort to the task, whether we have in mind what's happening in the world, or anything else. Understanding doesn't come free. But it's feasible for anyone who is part of a cooperative community -- Same holds for "intellectual self-defense."
By Noam Chomsky
-
Feb 26th, 2006, 12:11 PM
#5
Re: How to output part of feild using mysql and php
 Originally Posted by AWC_Joe
Not sure what your looking for... heres somthing i used to display mp3s from a Dir i would pass via url.com?folder=foldername
PHP Code:
if ($handle = opendir($_GET['folder'])) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (preg_match('#^(.+).mp3$#', $file, $match)){
$files[] = $file;
} else {
$dirs[] = $file;
}
}
}
closedir($handle);
if (count($dirs) != 0) {
sort($dirs);
//echo "".$dirs[];
}
if (count($files) != 0) {
sort($files);
}
}
echo "Sub Folders<hr align='left' width='74%'>" ;
for ($i = 0; $i < count($dirs); $i++) {
echo "<a href='?folder=".$_GET['folder']."/".$dirs[$i]."'>".$dirs[$i]."</a><br />" ;
}
echo "<h2><hr align='left' width='52%'>".$_GET['folder']." (".count($files).")<hr align='left' width='52%'></h2>";
for ($i = 0; $i < count($files); $i++) {
$date = date("M j Y",filectime($_GET['folder']."/".$files[$i])) ;
$size = formatsize(filesize($_GET['folder']."/".$files[$i])) ;
echo $date." <a href='".$_GET['folder']."/".$files[$i]."'>".$files[$i]."</a> - ".$size."<br />" ;
}
That is not a very safe peice of code to use as you could supply the path to any directoy on the server in the URL.
-
Feb 27th, 2006, 05:20 AM
#6
Member
Re: How to output part of feild using mysql and php
 Originally Posted by visualAd
That is not a very safe peice of code to use as you could supply the path to any directoy on the server in the URL.
That crossed my mind, but the idea was to list off all mp3s in the dirs with cleaner details then just opening up the dirs for browsing. By limiting what files can be displayed with preg_match, would you still say its unsafe (with the intent i stated) ?
Thanks for your input.
_
-
Feb 27th, 2006, 07:45 AM
#7
Re: How to output part of feild using mysql and php
I guess that depends upon whether you mind people searching for mp3 files elsewhere on your server.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|