Solved

php count the file is folder

Posted on 2013-02-01
3
337 Views
Last Modified: 2013-03-05
I have this code works fine if i leave the directory the blank will count the the number if files
<?php

$directory = ' ';
$images = glob($directory . "*.txt");


$filecount = count(glob($directory . "*.txt"));
echo "<p><b>";
echo $filecount;


?>

Open in new window

but  when I want to do this it does not work
<?php

$directory = 'C:\Projects\test';
$images = glob($directory . "*.txt");


$filecount = count(glob($directory . "*.txt"));
echo "<p><b>";
echo $filecount;


?>

Open in new window

also would need some code to allow across a network eg \\\192.168.0.1\folder
0
Comment
Question by:beridius
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Expert Comment

by:Chris Harte
ID: 38844021
The php server does not have access to the c:\ drive.  When left blank it will default to the root of the server, this is where the server is located on your hard drive, not the root of the hard drive.
0
 
LVL 2

Author Comment

by:beridius
ID: 38844048
so would I have to use ../../ to located my folder that I need ?

 but even i just put /test it does not work?
0
 
LVL 17

Accepted Solution

by:
Chris Harte earned 500 total points
ID: 38844089
Depends where the folder is. The default installation directory in windows is

C:\Program Files\Apache Software Foundation\Apache2.2

in linux it is

/var/www/html/

To the php server, this is the root, it cannot go above this. All the directories you want to work with have to be in this root directory.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question