Solved

php count the file is folder

Posted on 2013-02-01
3
324 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 16

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 16

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
count download link and run update query 9 55
Animated .jpg? 13 59
Amazon Redshift 2 25
javascript date picker in php while loop 5 24
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now