Quote:
Originally Posted by Publisher Bucks
Thats not an option unfortunately.
|
Why? If you're having to rename files if they exist, it can't be that important for them to strictly match the original name.
The files are effectively renamed when you upload anyway, when they're in the tmp directory, and when you move them from tmp you're 'renaming' them back to the original name, so instead you just pick a new unique name that you control that won't clash.
Anyway, if there's still some reason you can't do that, here's a basic code illustrating renaming of an uploaded file only if it exists. Save it as a PHP file and try it. Obviously change
$up_dir to whatever you're using.
Code:
<?php
$up_dir = 'upload/';
$tmp_name = $_FILES["image"]["tmp_name"];
$name = basename($_FILES["image"]["name"]);
if (file_exists($up_dir.$name)) {
// rename file however you like, eg:
$name = $name.'_'.time();
}
move_uploaded_file($tmp_name, $up_dir.$name);
?>
<form enctype="multipart/form-data" action="" method="post">
<input type="file" name="image">
<input type="submit" value="Upload">
</form>