Well, you should first be aware that if a file with the same name exists, the old one would be overwritten. Now when you say "image exists", do you mean that they inputted an image?
THis so far will check if image exists, and if user inputted image:
PHP Code:
<?php
$img = "images/".$_FILES['bilde']['name'];
$t=0;
while(file_exists($img)){
$img = "images/".$_FILES['bilde']['name'];
$img=substr($img,0,strpos($img,".")).$t.".".strstr($img,".");
$t++;
}
if(isset($_POST['blide'])) { if user inputted an image
if(file_exists($_FILES['blide']['name'])) { // if file exists already
echo "This file already exists in this directory.";
} else { // all req. met, upload file
move_uploaded_file($_FILES['bilde']['tmp_name'], $img);
echo "File successfully uploaded.";
}
} else { // if user did NOT input an image
echo "You must input an image first!";
}
?>
and your form should look like:
Code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
File: <input type="file" name="blide" />
<input type="submit" value=" Upload " />
</form>
&& like Jason said, you should probably go thru PHP and HTML tutorials first.
HTH
Bookmarks