Solved

How to compare files in a directory?

Posted on 2008-06-16
2
230 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:
Vel Eous 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

813 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

17 Experts available now in Live!

Get 1:1 Help Now