Solved

How to compare files in a directory?

Posted on 2008-06-16
2
228 Views
Last Modified: 2009-07-29
Hello group,

is there any function in PHP that we can use to compare two files? in my web application user is allowed to upload a file but I need to check if there is an existing file with the same name before the upload is complete.

Thanks!
0
Comment
Question by:akohan
2 Comments
 
LVL 14

Accepted Solution

by:
Tchuki earned 125 total points
ID: 21798211
Try:
if ( $dir = opendir ( "." ) ) {
 

	while ( $file = readdir ( $dir ) ) {

		if ( $file != "." && $file != ".." && $file != "index.php" ) {

			if ( file_exists ( $the_file ) )

			{

				echo "Filename already in use";

			}

		}

	}
 

}
 

closedir ( $dir ) ;

Open in new window

0
 

Author Comment

by:akohan
ID: 21860307

Thanks.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 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

13 Experts available now in Live!

Get 1:1 Help Now