Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Return The Amount Of Files In A Folder (including Subfolders)


Are there any functions available in php that will count the amount of files in a folder + its subfolders and return the answer? I'm sure there must be a simple answer for this.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How Can I Return The Number Of Files In A Folder?
How can i return the number of files in a folder?

Return All The .html Files In A Folder?
I'm trying to find all the include files in a folder is there a way to some how read a folder and then return an array with all the file names as the array keys or associative keys? I only want to return files that are .html or .php not all files

Limit Folder (with Subfolders) Capacity
I need to implement the next and I don´t know how to do it:

I am developing a website in which users are signed up and share
information(Messages, Photos...).

When a user is signed up, his data is stored in a database and he is
asigned with a folder.

What I need, is to limit the folder capacity of each user to a given
size(5 mb for example).

For now all users would have the same capacity.And that would be
enough for now.

I Can´t limit this by code, because I am using third party software,
in some services, and I cannot control It.

I have read about something disk quotas.I am not
familiar to this.Would it be useful for my needs?.

If not, Which is the best way to achieve this?.

The ideal for me would be to be able to limit the capacity of a given
folder(included subfolders) to a size, so when I create the folder in
my code, I would also limit its size to the desired capacity.

Note: I am using php5 and my hosting uses linux.

Including Files In Different Direcories That Include Files From Teirs
Okay, I made a simple AJAX shoutbox and I want to include it on all my pages. To insert the shoutbox I simply type <? include('/shoutbox/shoutbox.php');?> into my HTML page.

The problem is, that in /shoutbox/shoutbox.php I also include settings.php, functions.php, and some other files, and when I include /shoutbox/shoutbox.php into my index page, /shoutbox/shoutbox.php tries to call settings.php from the same folder that my index file is in, since I just 'included' it in index's source.

So my question is, is there any way, without using frames, to include a PHP file as it would be if you link directly to it in the address bar, but placed into another file in a different directory?

Drag Files From One Folder To Another Folder (copy) .. Possible?
Is it possible to write codings PHP or Javascript.. GUI representation
of File handling (ie. Drag files from one folder to another folder (copy)
like our windows).. pls give me some reference codings like this..

Including Files In Other Directories
I have some code running on windows on my local machine that uses the
jpgraph image library. I include the jpgraph libs using

include ("C:Programmingphpjpgraph-1.14srcjpgraph.php");

I am trying to get this code to run on my web host's unix server, with
no luck.
I put the folder (jpgraph) containing all the jpgraph libs in the same
directory as my php code. I have tried all of the following:

include ("/jpgraph/jpgraph-1.14/src/jpgraph.php"); //(relative
path)

include ("jpgraph/jpgraph-1.14/src/jpgraph.php"); //(relative
path without leading slash)

include ("/usr/www/users/mysite/jpgraph/jpgraph-1.14/src/jpgraph.php");
//(absolute path)

include("http://www.mysite.com/jpgraph/jpgraph1.14/src/jpgraph.php");
//(url)

include ("http://" . $_SERVER['HTTP_HOST']
. "/" . dirname($_SERVER['PHP_SELF'])
. "/" . "jpgraph/jpgraph-1.14/src/jpgraph.php");

None of these have worked. Does anyone know the proper technique to
include files in other directories when using Unix or Linux? Keeping
all php files in the same directory is not feasible.

Trouble Including Files
I am trying to include a file in a lot of my pages, but I am running into some problems.  I put an echo statement in the included file and that's showing up fine, but none of the variables are making the transition. Can someone enlighten me? I have no clue what could be going wrong.

Including Files In Remote Server
I have a perl script to grap headlines from slashdot and such for me, and I use corn to have it run hourly and put the headlines in a file on the linux server.

Now problem is that my site is sitting on a Windows 2000 Apache Server. So I can't seem to use include() to get the file into my page. Any suggestions or alternatives?

Including Files From Entire Directory
I have this little news script that stores each entry into a seperate file into monthandyear/day, month date, year hour-minutes-seconds AM/PM

so if it was Sunday, March 9, 2003 11:39 PM then the script would store the new entry in the folder named "March2003" and in a file called "Sunday, March 9, 2003 11-39-00 PM"

now, the problem i have is i want to have an archive of all my news entries by month, so how do i get the contents of all the march entries displayed onto one page in order of date and time?

Problem With Including Files In Windows
did all of the development originially on linux - everything works great. started moving it over to windows, i can't even get the main page to load. i have 2 files included on the index.php page:

1. ) config.php - houses db connection function & some sql functions
2. ) functions.php - has functions to display data based on what page you're on, etc.

the problem is i can't include the config file.

index.php times out after 30 or 60 seconds; without it, i have alot of code to fill in all over the application. i made some small changes to it, even tested it again on the linux box and it still works, however when i test it on the Windows machine it, as stated, times out. when i don't include config.php, the page loads alright, just with "call to undefined function: sql() in c:inetpubwwwroothtmlincfunctions.php on line 23" scattered where i have my db calls.

Require_once(), Seemingly Including Files More Then Once.
I don't know if anyone has run into similar problems, but it seems like
when I use `require_once(...)' with files that contain functions I get
an error indicating that it can't redeclare the functions. I thought
the point of the once directive was to PREVENT the system from
including duplicate files (and thus attempting to redeclare the
functions).

It has worked elsewhere, for instance I have a database.php file, that
just wraps the mysql database query functions into my own functions. I
have used it in the following manner in two files one that calls
another:
require_once "./directory/database.php";

And it works fine, it doesn't give me any errors about redeclaring
functions.

Now when I do the following in one file:
require_once "./directory/database.php";

and the following in the file the first calls
require_once $DOCUMENT_ROOT . "/directory/database.php";

I get the redeclare error. Is this because the system is perceiving
these as two seperate files? Syntax wise the above two work exactly
the same as if I had parantheses (I thought this might be the cause of
the error) but it wasn't.

Including Files That Have Query Strings
I am having trouble with accessing files with query strings. For
example the code "require 'template.php?102932'" gives the following
error:

Warning: main(/www/blog/template.php?102932): failed to open stream:
Invalid argument in C:wwwlog20041227est-of-2004index.php on
line 54

Fatal error: main(): Failed opening required
'/www/blog/template.php?102932' (include_path='.;c:php4pear') in
C:wwwlog20041227est-of-2004index.php on line 54

I have no idea what's going on. Is it impossible to open files with
query strings in PHP? I am running PHP 4.3.9 on Apache 2/Win.

Including .txt Files With Html Content
I have a php page and I want to include some txt files within it depending on the URL variable. For example, I have some text files (that contain html code) with these names:

cat.txt
dog.txt
parrot.txt

How can I make the contents of, say, "parrot.txt" appear on the page, if I use a URL like: mysite.com/page.php?c=parrot

"c" stands for "content" and each time I want to include a file, I would use the exact name of the txt file - but without the .txt extention.

I know this is possible and I had the code to do it but it's been over two years and I have misplaced the code.

How To Detect Number Of Files And Files' Name In A Folder?
I have a server built in window + apche. I am trying to make a photo album, but I don't know what is the code for detecting the number of files in a server folder and the files' name~.

Embeding/Including A Flash Movie That Uses Xml Files
I use a flash movie in a certain directory lets say: english/products/<prod_id>/gallery.swf

That movies uses the files: settings.xml, menu.xml, splash.jpg that are in the same directory as the flash, and /images/pics.xml and pictures in that directory and pictures in the /images/thumbs/ directory. I can embed the flash fine in a gallery.php file that is in the same directory as the swf file.

Here are the problems: When i try to include that gallery.php file in the /english/offer.php?id=x file the movie doesn't load

If i try to embed the movie in the offer.php the movie loads ok but can't find the files it needs to work correctly. I moved the files in the /english/ directory and the movie loaded ok so by embeding the movie in offer.php it makes the swf look for the files in /english/ directory instead of english/prod_id/

I can't hardcode it in the flash movie because its a user gallery and each user will have his own gallery and files. And i m not that good at flash so i dont know how to change the flash so it would use parameters from php.

Is there a way in php to include or embed the flash movie and force it to read the files from the correct directory?

Trouble Including Relative PHP Files From Cron Jobs
I have a php file /home/mysite.com/httpdocs/admin_section/report.php that as part of the script includes another file ../connections/connect.php.

Report.php works perfectly when I open it from a webbrowser (mysite.com/admin_section/admin.php), but when I run from my crontab or command line via:

# /usr/bin/php /home/mysite.com/httpdocs/admin_section/report.php

The report.php file then chokes on the include.

"PHP Warning: main(../connections/connect.php): failed to open stream: No such file or directory in..."

And the strange thing is this used to work before my server was upgraded by tech support. If I get rid of the relative path and include the full server path to connect.php, it works perfectly (but because I have a number of scripts like this, it isn't practical for me to change any of the PHP code).

Any ideas on how I can fix this?

Including Files With Images And Relative/absolute Addresses
I have an included file (header.php) that contanis a reference to a graphic.
If I stay at the root level, then I can control the relative path of the
image.
eg. images/imagename.jpg

However, if I include this file (header.php) in a lower level directory then
of course, I end up with no image displaying as the relative path is no
longer correct.

Currently I am using the following to provide an absolute path to the image.

$path = "http://".$_SERVER["HTTP_HOST"]."/images/";
$image = $path."imagename.jpg";
echo "<img src="$image">";

This works fine, but looks klunky.

I would like to avoid specifying an absolute hardcoded path name so I can
load this function on any site I choose.

how to get images displaying when including a
header.php file in a lower lever directory?

Strategies For Including Files When You're Not Allowed To Make Assumptions About Directory Names
1.) Can anyone think of a way to speed up this function? It is
terribly slow. I plan to reduce the number of directories to 3, which
I guess will speed it up in the end.

2.) This seems to be the brute force method, and I'm wondering if
anyone can think of a better strategy. I've been asked to make life
easy on graphic designers by not making assumptions about where I
might find the files that the software might need to run. The files
might be in the same directory as the main file, or in directories
above, or in ones below. The person may have remembered to put a
".php" at the end of the file name, or maybe not. Here I simply go
looking. Is there a more graceful strategy than this? Some kind of
regular expression thing maybe? ...

How To Get The Files Names From The Folder Using PHP ..
How to get the files names from the folder using PHP .. is there any
specific command. If yes let me know that..

Paging Of Folder Files
i have a form which has a select button when user clicks it a popup opens which shows all images in abc folder
 
when user clicks on any image the window closes and the name of that image is entered in the text box in parent form, now its working fine uptill here but if user refresh the popup window then it disconnects from parent window so my code that fills the textbox in the parent form and closes the popup window does not work anymore im using it like parent.document.form.texthox.value=abc since popup window is refreshed it does not work as child any more and this code does not work.

Files And Folder Copying
I am trying to write a function to copy an existing folder and folder
structure but am already stuck.

What I want to do is the following:

Copy a default folder (default_folder) and all sub folders within it (down
to a possible 4 levels)
eg default folder
->subfolder1
->subfolder2
->sub subfolder1
->sub sub folder 2

I have a form where the user can enter the name of the new folder and an
option to confirm if they want to copy the files also located within the
default folder.
If the checkbox is not checked then copy just the folder structure only

Can this be acheived in one function or will it be based on 2 where a set of
empty folders are created and where the folders and files are copied over

What Is The Max PDF Files Allowed In A Folder?
Not sure where to put this question? I am building a book archives database with a front-end for some librarians. They want to upload book cover images onto the server (probably Win-NT). There are approximately 80000 records that will have the book cover images stored in a PDF document for each. Can I upload every PDF to the same folder? Is there some kind of limit for a folder?

Deleting Files From A Folder...
I have a folder with many pictures in it.
All have the name like: HHMMDDMMYYYY.jpg

H-hour
M-minute
D-day
M-month
Y-year

Now I want to delete all pictures which are older than now()-7days.
How Can I do it? In SQL would be no prob but with file deleting is problem.

Opening Files In The Same Folder..
I have a php file (1.php) that needs to open another php file (2.php) and parse it's output. 2.php gets it's data from an xml file and formats it in a pretty screen style. So what I need is something like: $fp = fopen ("2.php?file=file.xml","r"); but that wont work because there is no file called &#392;.php?file=file.xml' so how's it done?

Root Of Folder App Files
While I know putting a app into a folder was chiseled out of fine
scottish granite and carried upto the top of ben nevis by php newbies
many years ago - I dont think a folder is the best way to do it .

The fact a script is in a folder means certain instant problems if you
want to do certain things with .

Assuming a script doesnt have index.php and all the script files have a
filename prefix like phpgb_ then theres no chance of them clashing with
anything else and theres no real reason to continue using a folder for
the main script files .

While the script will have a app folder for various things - does it
make any sense not to use the root because of a single solitary file
called index.php .

phpgb_index.php is what I use and the method hasnt brought up a single
problem of any shape or description .

Gas lighting was once what everybody thought was the best way of doing
it until that darn new fangled electricity came along .

1 - 2 Millions Files In One Folder?
I have to store over a million files, 10 - 15 kb each, in one folder.
The files are created by my php script, sometimes the old files are
deleted and new ones are written.
So, basically on every connection my script reads/deletes/ writes files
from/to that folder.
Right now i have only around 300 000 files in that folder, and it feels
like its getting slower for that script to work. It does work at the
moment, but i am not sure what will happen when there is over a million
files there...
Are there any limits of files that can be stored in a folder?
Would it be better for me to use mysql? I am not sure how mysql will
cope with millions of writes/reads

How Does One Get A List Of All Files In A Folder?
need a list of all files (i have like 5k or so) in a folder, I need to add there names to a table

I am doing this so i can compare two tables

table 1. comments added to uploaded pics -finished pictures-
table 2. no comments added yet to uploaded pics (so they can be commented on GET IT?)  -unfinished pictures-

All the pictures are in a single folder for the time being i'm going to be making a form based on the pictures that are on table 2 so that they can have comments and titles and file name added to table 1 (to be done still) but i need to know all the file names for the folder in question, i guess i could do it via cmd line ls or something like that, i'll get back to you.

Pagination W/ Just Files In A Folder?
Example would be:

prev 12345 next

but doing this with just files and not DB records?

Viewing Files In A Web Folder
I'm trying to put my files in a web dirctory.  All kind of files, so that in the future when I need something I just go there and get them.  My goal is that when I type "www.domain.com/myVitualDirectory" I would get my list of files and folders and files and I would even be able to navigate into the folders, then I would right click and Save Target As and get my file.

Php Include Files From A Folder
I want to make a folder filled with blog posts by date.  Each file will be like 20071113.php and 20071031.php basically the date they were written 2007, 10 for october, and 31 for the day.  But each will be notated like that so that the number is always increasing. 

How would I make a php include function as to take the last ten highest numbers and add it to a page? (Basically the last ten posts by date) and  How would I include more than one post per date?

Indexing Text Files In A Folder
I'm newbie on Php. I cannot write codes but only modify.
I need a code doing this:
I'll put text files in a folder like file1.txt,file2.txt ...
I want to search this files, list most recent 10 and if files

call, script will put into the site design with <pre> tags.

Dropdown List Of Files In Folder
I am preparing a form that includes a drop-down list consisting of the names of files in a certain folder on the server.

I only need to trap the file name (jpg), not the path and I'm not trying to upload the files or anything - simply allow the user to select one of a number of different image files (they're actually location maps).

Recursive Copy Of Folder/files
I want to copy entire content(have both files and folders)from One folder to destination folder..

Opening All Text Files In A Folder
Im very new to php and need a bit of help. basically what I have is a folder with a number of text files inside. What i need to do is open every text file in that folder and then process the information inside each text file.

Im not really sure but I would assume I open the directory and place the name of each text file into an array and then loop through the array and process the contents of the text file.

#open directory

#foreach text file in the directory
#store file name into an array

#loop through array
#process code

Display A List Of Files In A Folder
How do you display a list of files in a folder and then delete one by clicking on it?

Displaying Files In A Folder Using A Calender
I have excel sheets generated daily and weekly in this format for filenames..for daily sheets the filename is Jan-10-2002 (mmm-dd-yyyy) and weekly Week-39-2002. I have a script that uploads to a constant folder all the excel sheets.

Is there a script that can display the daily scripts in form of a calender. I.E a user can choose to view or download the sheet by choosing the date? Also another for displaying weekly excel sheets in a weekly format.

Show Html Files In A Folder
I am trying to create a script that will parse the folder it's containing php page is in for html files. Create a drop down list of links to the html files.
Anyone know how I might do this?

Deleting Files In A Folder Modified Before Certain Date
I use a cache system that requires creation of files in a folder .

Now , what i need to know is how can i delete files created say 3 days ago.

So that the cache remains fresh.

The directory contains around 20,000 files , about 10,000 are generated each day (if they dont exist)

So getting info about the each file after using opendir will cause the server to slow down.

Download-scriptto DL Files Outside The Public_html Folder
I have a small Linux webserver, and want to find a (php) script
that lets my users download files located outside of the public_html
folder.

Include Files Folder - CHMOD Settings?
Currently, I have various php files in my "public" folder on my webserver. I also have "include" php files in a designated folder w/in my "public" folder (i used include("file")

Example: path files

public folder => index.php, products.php, aboutus.php, etc
public folder/include folder => includefile1.php, includefile2.php, etc

what CHMOD settings should i set... so that users cannot directly open my "include" files? and where do i set them? on the "include" folder? on the individual "include" files?

Detecting PDF Files In A Folder And Sorting Them By Date
I am about to write an application that will display all pdf files in a
folder and display them by file name in order of date.

Is there an easy way of doing this? I was thinking about somehow adding
filename and date created in an array, sorting by date and then
printing onto an html page with a link to that file. How would I do
this though? Is this the simplest method or is there a better way of
doin this?

Uploading Mp3 Files To Folder On Server Via Php Form..
Im trying to design a webpage form in php that allows uploading of three mp3 files to a folder on my server. The webpage should convert the name of each mp3 file uploaded to 1.mp3 , 2.mp3 and 3.mp3 and whenever a new song is uploaded it should replace whatevers in the folder on the server, im totally stuck as where to begin.

I Can Upload Files Anywhere Except My Remote Root Folder
Im working on a project with PHP that allows users to upload pictures to my server and then reference them. After going through some uploading tutorials I have the uploading part working Except! I cant upload folders to my remote root folder. I need to allow the users to upload somewhere inside the root folder so they can reference the pictures in code after.

Just to clarify the uploading works perfectly if I put the uploads folder anywhere on my computer except the sites remote root folder (or anywhere inside the root folder)
I also beleive I am giving the folder all of the proper permissions because I am giving the uploads folder in my root directory (the one that doesnt work) the same permissions as the one outside the root (the one that works) Code:

Some Files Created Automatically In Mysql Database Folder
i have created one database in mysql. first i have created all tables
are of innodb type then i converted all tables to myisam type. i know
that for each myisam type table three files are created tablename.frm
tablename.myi and tablename.myd.

i have created database before one month. today i checked database and
i show somefiles exist in database folder named
(1)#sql-644_27.frm
(2)#sql-644_1.frm
(3)#sql-638_1.MYI
(4)#sql-638_1.MYD
(5)#sql-638_1.frm
(6)#sql-478_5.frm

can anyone tell me what is these files and why is these files?

Display Contents Of Subfolders
I am trying to make a script to display contents of a folder and any subsequent subfolders, but I don't know how to move into a subfolder and display the contents.

What Image Url To Use For Pages In Different Folders/subfolders?
suppose in my root folder i have

image.jpg
page1.php
->subfolder

and inside subfolder i have page2.php

if i want to insert image.jpg into both page1.php and page2.php, and i want to use only one and the same image URL for both pages, how should i do that? Code:

Managing Imap Subfolders With Web Based Mail
I am attempting to write my own webmail client with php to interact with an imap server. I have looked at other systems to get an idea of how to implement folder management without success.

The php imap functions don't seem to deal with this at all. There are functions to list mailboxes but not subfolders. Specifically I need to:

Display a list of subfolders
Display the messages in each subfolder
Delete and move messages form subfolders
Create Subfolders
Delete subfolders

From the other webmail clients I've seen only Squirrelmail seems to deal with folder management and for the project I'm involved in I need to create my own client.

How To Move Files To The "lib" Folder?
A client recently asked me to move a lot of code into the "lib" folder...and I'm not sure exactly how to do this without having the site blow up.

I'm using Subversion and have a root-level folder structure that looks like this:
* lib
* logs
* sql
* src

Currently, I have all of my web files in the "src" folder.

There is a folder of include files in the "src > includes" folder. The client is asking to move these to the "lib" folder for security reasons.

How do I do this?!

I'm not sure how to move files outside the "src" folder and have the site still function properly.

Remove From $name (folder)/(folder)/[x]/ <-- If Exists To Just Get [x].
I'll be quite honest. I don't have the faintest idea
how to do this, while I can do other php without a problem. Once I
know how to go about it I'll be okay.
It's two things I think?
1. see if there's a trailing slash and delete it.
2. Remove the preceding path to /x, the folders and slashes, and
delete them.
and then I have x.

X by the way is the final folder in a website and this grabs it for
me.

<?
$name = $REQUEST_URI;
?>


Copyright © 2005-08 www.BigResource.com, All rights reserved