Avatar of Richard Korts
Richard Korts
Flag for United States of America

asked on 

Can't get directory files in php

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:// www.xyz.com/uploads/"

Same result.

Thanks
PHP

Avatar of undefined
Last Comment
gr8gonzo

8/22/2022 - Mon