New Articles

Security issues in FTP.

PHP File upload progres bar.

The case of the missing errors.

Directory Browsing with PHP

If you feel that the directory browsing api in PHP is rather cumbersome you would suprised at how easy it is to browse your file system with PHP.

The backticks operator - the (') character provides means by which you can execute system commands. This can be combined with the most famous of linux commands `ls` to obtain a listing of a given directory.

The output from the ls command will be available as a php variable. The variable is a string where each entry in the folder is separated by a new line. The second step in your code would be to split up this long string into an array and process it line by line with a loop. Let's look a very simple piece of code to do this

		$list = split("\n",`ls -l`);

		$pattern = "/[dwrx\-]{10}/";

		foreach($list as $file)
			$file = preg_split("/ /",$file,20,PREG_SPLIT_NO_EMPTY);

			echo join("|",$file) ."\n";
			//echo "$file[0]\n";

These few lines of code just splits up each record into it's components but doesn't do anything usefull. In the next page next page you will see a usfull example.