file exists problem

file exists problem

am 02.01.2008 20:10:43 von Karl

Hello again.
I use this file-upload example below. But I want to check if a file
exists. I have tried to put the file_exists() function inside of this.
But it did not work well..

(The example below is taken from Oreillys PHP Cookbook and it work
nice. But it overwrite existing files and I like to receive an error
and protect files on the server from this.)

Thanks for all advice.

Karl

// *** Nyhets Bilde ***
if (isset($_FILES['nyhets_bilde']) &&
($_FILES['nyhets_bilde']['error'] == UPLOAD_ERR_OK)) {
$bildesti = '../nyheter/' . basename($_FILES['nyhets_bilde']
['name']);
} else {
$bildenavn = basename($_FILES['nyhets_bilde']['name']);
if(move_uploaded_file($_FILES['nyhets_bilde']['tmp_name'],
$bildesti)) {
} else {
$nyhets_bilde = "$bildenavn";
} else {
$nyhets_bilde = "Kunne ikke flytte bilde til $bildesti";
}
} else {
$nyhets_bilde = "";
}