troubleshooting Question

Can't get directory files in php

Avatar of Richard Korts
Richard KortsFlag for United States of America asked on
6 Comments1 Solution20 ViewsLast Modified:
Iv'e done this before, can't remember exact syntax:

$dir = "/uploads/";
$files = scandir($dir);
$nf = count($files);
echo "nf = " . $nf . "<br>";
for ($i = 0; $i < $nf; $i++) {
	echo "file = " . $files[$i] . "<br>";
	if ($files[$i] != "." && $files[$i] != "..") {
		// check for Rep List
		if (strpos($files[$i], "Rep List")) {
			copy("/uploads/" . $files[$i], "/workspace/Rep_List.xlsx");
		// check for Price Sheet
		if (strpos($files[$i], "Price Sheet")) {
			copy("/uploads/" . $files[$i], "/workspace/Price_Sheet.xlsx");
		if (strpos($files[$i], "Movement")) {
			copy("/uploads/" . $files[$i], "/workspace/Movement.xlsx");

Open in new window

uploads is a directory underneath the directory with the php program.

It contains 3 files.

Running this produces:

I know it produces 2 files (. and ..) even if the directory is empty.

nf = 1
file =

What's wrong?

I tried $dir == "../uploads/

and $dir ="http://"

Same result.


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros