Go Back   Free website templates > Web Template Help > PHP and MySQL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Join now to share free website templates or post on the forum. If you have never been on a forum before read the FAQ. It's quick, easy and free to join!
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-18-2008, 08:28 PM
pezboy45's Avatar
Mod/Design & Coder [Pro]
 
Join Date: Nov 2006
Location: Hawaii
Posts: 685
pezboy45 is on a distinguished road
Send a message via AIM to pezboy45 Send a message via MSN to pezboy45
Exclamation File Counter

Ok, so here is what I need/looking for.
I need a php(java works too) script that counts the amount of a certain file in a folder.
I've seen it done, but I can't seem to find a way (that works)

Basically I just need it to say: Currently Shuffling __ Songs!
So, if anyone could help me on this..that would be great!

Thanks!
__________________


If I ever don't follow up on something, please feel free to PM me. I've got a lot going on, so a friendly reminder helps.
Reply With Quote
  #2 (permalink)  
Old 10-22-2008, 12:17 AM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,772
ishkey will become famous soon enough
Default

This part has got me confused
Quote:
that counts the amount of a certain file in a folder.
Do you want to only count a certain file type in a directory or all files in that directory and then display Currently Shuffling 12 Songs! or whatever the count is?
__________________

Consultant - Programmer - WebMaster
cleandeck - lawn mower undercoating
wilmargraphite - graphite lubricants
Reply With Quote
  #3 (permalink)  
Old 10-22-2008, 03:17 AM
pezboy45's Avatar
Mod/Design & Coder [Pro]
 
Join Date: Nov 2006
Location: Hawaii
Posts: 685
pezboy45 is on a distinguished road
Send a message via AIM to pezboy45 Send a message via MSN to pezboy45
Default

Quote:
Originally Posted by ishkey View Post
This part has got me confused

Do you want to only count a certain file type in a directory or all files in that directory and then display Currently Shuffling 12 Songs! or whatever the count is?
Yea, like I want it to only count .mp3 files.
Reply With Quote
  #4 (permalink)  
Old 10-22-2008, 10:53 AM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,772
ishkey will become famous soon enough
Default

I'll see what I can do.
__________________

Consultant - Programmer - WebMaster
cleandeck - lawn mower undercoating
wilmargraphite - graphite lubricants
Reply With Quote
  #5 (permalink)  
Old 10-22-2008, 09:07 PM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,772
ishkey will become famous soon enough
Default

Give this a try.

<?php
$total_mp3_file=count(glob("*.mp3"));
echo "Currently Shuffling ".$total_mp3_file "Songs";
?>
The above example will take from the current directory. To search a specific directory you can use the following. (changes the first line)
To list number of mp3 on a particular directory you can use something like this.
<?php
$total_mp3 = count(glob("/path/to/mp3/{*.mp3}", GLOB_BRACE));
?>

************************************************** **********************
to simply get a count of files in a given directory

<?php
//get path of directory containing this script
$dir = $_SERVER['DOCUMENT_ROOT'].dirname($PHP_SELF);
//open a handle to the directory
$handle = opendir($dir);
//intitialize counter
$count = 0;
//loop through the directory
while (false !== ($file = readdir($handle))) {
//evaluate each entry, removing the . & .. entries
if (is_file($file) && $file !== '.' && $file !== '..') {
$count++;
}
}
echo $count;
?>
or if you prefer, assign the $file variable to an array in the loop:
if...{
$files[$count] = $file;
$count++;
}
then you can return either $count or count($files) to get your number of files.
__________________

Consultant - Programmer - WebMaster
cleandeck - lawn mower undercoating
wilmargraphite - graphite lubricants
Reply With Quote
  #6 (permalink)  
Old 10-23-2008, 02:47 AM
pezboy45's Avatar
Mod/Design & Coder [Pro]
 
Join Date: Nov 2006
Location: Hawaii
Posts: 685
pezboy45 is on a distinguished road
Send a message via AIM to pezboy45 Send a message via MSN to pezboy45
Default

Wow, I'm testing it right now!!!
Thanks!!
\\\\

Ok, I get an error:
Code:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/.uris/dahost/infinisound/index.php on line 107
I'm trying to figure out the second code you game me, the one after all the "*****".
But, if you have any answers let me know.
Thanks.
Reply With Quote
  #7 (permalink)  
Old 10-25-2008, 11:49 PM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,772
ishkey will become famous soon enough
Default

let me see your code.
__________________

Consultant - Programmer - WebMaster
cleandeck - lawn mower undercoating
wilmargraphite - graphite lubricants
Reply With Quote
  #8 (permalink)  
Old 10-26-2008, 12:03 AM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,772
ishkey will become famous soon enough
Default

Forgot - This error is encountered when running on PHP 4.x and on a shared hosting. Update to PHP ver 5.x and try again.
__________________

Consultant - Programmer - WebMaster
cleandeck - lawn mower undercoating
wilmargraphite - graphite lubricants
Reply With Quote
  #9 (permalink)  
Old 10-29-2008, 10:04 PM
pezboy45's Avatar
Mod/Design & Coder [Pro]
 
Join Date: Nov 2006
Location: Hawaii
Posts: 685
pezboy45 is on a distinguished road
Send a message via AIM to pezboy45 Send a message via MSN to pezboy45
Default

Quote:
Originally Posted by ishkey View Post
Forgot - This error is encountered when running on PHP 4.x and on a shared hosting. Update to PHP ver 5.x and try again.
I'm running 5.x.x
I am on shared hosting, but that shouldn't really effect it because we all have our own virtual servers.
So, I'm really confused on what to do.

(Thanks for your help though)
Reply With Quote
  #10 (permalink)  
Old 10-29-2008, 10:54 PM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,772
ishkey will become famous soon enough
Default

Is that your girlfriend??? or is she just WOWing us.
Parse error: could be the line it is showing or it could be a line somewhere else. Hard for me to guess at, easier with the code, to look at to solve problem. Promise I won't give it away.
yes you are right shared server is not a problem.
__________________

Consultant - Programmer - WebMaster
cleandeck - lawn mower undercoating
wilmargraphite - graphite lubricants
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:06 AM.



mouseover mouseover mouseover