Jump to content

[SOLVED] $match_found wont store the value


clown[NOR]

Recommended Posts

i'm currently messing around with file uploading, and i want to check if there's allready a file with the same name so it doesn't overwrite anything... but I couldn't get it to work.. so i diabled the whole upload part and tried to echo out the result...

 

this is the code

<?php
$path = "files/";
$full_path = $path . basename($_FILES['uploadedfile']['name']);
$file = basename($_FILES['uploadedfile']['name']);
$match_found = false;

if (is_dir($full_path)) {
	if ($dh = opendir($full_path)) {
		while (($search = readdir($dh)) !== false) {
			if ($search == $file) { $match_found = $search; }
		}
		closedir($dh);
	}
}

if ($match_found) { echo "Found 1 match! (" . $match_found . ")"; }
elseif (!$match_found) { echo "No match found! (" . $match_found . ")"; }
?>

 

and all it returns to me is:

No match found! ()

 

any ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.