Solved

php count the file is folder

Posted on 2013-02-01
3
326 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
  • 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

770 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