Solved

How to compare files in a directory?

Posted on 2008-06-16
2
229 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

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

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 …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

867 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

16 Experts available now in Live!

Get 1:1 Help Now