Current location: Hot Scripts Forums » Programming Languages » PHP » PHP File counter


PHP File counter

Reply
  #1 (permalink)  
Old 05-03-05, 04:53 PM
brambulkens brambulkens is offline
Newbie Coder
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Question PHP File counter

Hi. im new here (and to PHP) (and please take ur time to read my question)

I know a bit PHP and how it works.
Part from that i know Actionscript well enough.
uhm... i won't bother you with myself so here's whatsup:

i'm making a webpage with a flash menu.
The website has a column page and de button in the flash menu refers to this page... butt, i constantly make new column pages in html (just the text, wich i load in an iFrame) Now what i want is that when u click in the menu on the column button that you will always get to see the last made column.

i called the column pages "column<number>.html" like " colomn8.html" etc etc. Every new column is named the last column +1 so after column8.html comes column9.html ... this means that when u press the button in flash u need to see the newest page (i.e. column9.html). Butt i DONT want to constantly update the flash button with a new linkscript.

[so far the website explanation]

So i tought, why not make a PHP script that counts the number of HTML files within the column directory... if the script can count the files it can create a link that it parses in a TXT file right?

so if the script has "variable" as the number of HTML pages within the directory you can let the script write a linkvariable like $link='column'+"variable"+'.html' (or something like that) and parse that variable of that $link within a TXT file

after that i can read out the variable whitin the textfile with FlashMX and use it as a link for a button, right?

-------------------------------------------------------

Is this possible, counting files within a folder with PHP? or do i need an other scripting language for that? or do you recommend an other way to handle this link within Flash to my newest column page (wich adds UP)

i really hope you took the time to read my question and that you would like to help me... i really do ... so much to learn.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-03-05, 06:10 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
yes it's possible to count files in a directory..
simply use scandir() function like this:
PHP Code:

$files = @scandir('mydir');


if (
$files)
   
$num_of_files count($files) - 2// we substract 2 because . and .. are included
else
   die(
'there is an error');

if (isset(
$num_of_files) && !empty($num_of_files))
    echo 
"There are $num_of_files files in the directory";
else
    echo 
'no files found!'
this will count the number of files found in the directory "mydir" and then assign the names to the array $files.
you can manipulate this array with foreach() like:
PHP Code:

$link null;


foreach(
$files as $file)
    
$link .= "column{$file}.html\n";

echo 
$link
this will print the files found like:
columnFILENAME.html

HTH
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 05-03-05 at 06:13 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-04-05, 06:12 AM
brambulkens brambulkens is offline
Newbie Coder
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
id really like to thank you, butt is there a way to parse the $link to a TXT file?
cus now it parses the link within the page that you putted the PHP in right?

and i tryed to putt the code in the main index.php butt nothing happens.
i cant get to see an number of files or an link.

do i use my @scandir right?:
$files = @scandir('html/text/column');

please help me...

(total noob alert)

Last edited by brambulkens; 05-04-05 at 06:28 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-04-05, 07:15 AM
brambulkens brambulkens is offline
Newbie Coder
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
okay i think iv done it.

the @scandir thing did not work sow i tried it an other way.

Code:
<?php

$dir   = 'html/text/column/';
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
   $files[] = $filename;
}

if ($files) 
   $num_of_files = count($files) - 2; // we substract 2 because . and .. are included 
else 
   die('there is an error'); 

if (isset($num_of_files) && !empty($num_of_files)) 
    echo "There are $num_of_files files in the directory <br>"; 
else 
    echo 'no files found!'; 

$link = null; 
$link .= "html/content/column/column{$num_of_files}.html\n"; 

echo $link; 
?>
how do i now read the $link into flash?
Do i need to write it to a txt file or can i read the variable into flash directly?

and do i need to putt this script into the index.php? only then without the echo parts right?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-04-05, 08:38 AM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
I believe there's only so far one question can go before you might as well just head for the script requests forum.

The script can go into whatever .php file you want it to run from, keeping in mind the relative directory references. You should then set the code to only output the one line of information that you need, then get flash to fetch it as you would any other file and do what you want to it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 05-04-05, 08:55 AM
brambulkens brambulkens is offline
Newbie Coder
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Sabu
I believe there's only so far one question can go before you might as well just head for the script requests forum.

The script can go into whatever .php file you want it to run from, keeping in mind the relative directory references. You should then set the code to only output the one line of information that you need, then get flash to fetch it as you would any other file and do what you want to it.
Butt that PHP file has to be a file that runs/is accessed, or not?
the thing is that i cant get it to work with flash... as i read the $link variable into flash... thats why id like to ask if the above script is the right way to do that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 05-04-05, 12:24 PM
brambulkens brambulkens is offline
Newbie Coder
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
someone told me to replace:
$link .= "html/content/column/column{$num_of_files}.html\n";

with:
$link .= "&link=html/content/column/column". $num_of_files .".html&";

butt i still cant get flash to see the $link variable in the index.php. the swf is also in the same index.php
Now i get a NOT FOUND error. He cant find /bram/link ("bram" is a the map where all the files are in (index etc))
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 05-14-05, 07:20 AM
brambulkens brambulkens is offline
Newbie Coder
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
NEW WAY OF WORKING:

Code:
on (release) {
var totalfiles = new LoadVars();
totalfiles.load("html/content/totalfiles.txt");
totalfiles.onload = function(){
goto = totalfiles.x};
link = "html/content/column/column"+goto+".html"getURL(goto , "content");}
With this script i get variable "X" from file "totalfiles.txt"
X will be putted there later bij PHP but is at this moment equal to "1"

Butt it doenst quet work the way i want ot to. If i look in flash at "List of Variables" of the FlashPlayer i see this:
Code:
Variable _level0.instance8.totalfiles = [object #1, class 'LoadVars'] { 
onload:[function 'onload'],    
x:"1"  }
Variable _level0.instance8.goto = "1"
Variable _level0.instance8.link = "html/content/column/column1.html"
De variables work as you see butt the button still wont take the variable as the link... verry strange. As in mather of fact as i click the button it opens the folder wich contains the index.php. The folder wich contains the path of the variable "link". If i putt it online and click the button, it wont do nothing at all...

What to do about it????
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 05:03 AM
Saving php generated file as html file GS300 PHP 0 12-29-04 04:34 AM
move files around an ftp server, with php file upload script? wapchimp PHP 2 12-19-04 08:27 AM
PHP code on a remote file tonniar .rm PHP 2 05-24-04 03:32 AM
compare the contents of 2 file in php rani PHP 5 04-15-04 12:47 AM


All times are GMT -5. The time now is 08:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.