?
Solved

How to compare files in a directory?

Posted on 2008-06-16
2
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
Vel Eous earned 500 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

762 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