Solved

How to compare files in a directory?

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
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 …

729 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