npsari
04-22-2007, 04:10 PM
I am using this upload file script:
<?
// Where the file is going to be placed
$target_path = "images/";
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['Image1']['name']);
$_FILES['Image1']['tmp_name'];
$target_path = "images/";
$target_path = $target_path . basename( $_FILES['Image1']['name']);
if(move_uploaded_file($_FILES['Image1']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['Image1']['name'])." has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
But everytime someone uploads the same image name, the image is over-written.
So this is a little problem because users might upload same image names
How can i prevent the script from overwritting old images
<?
// Where the file is going to be placed
$target_path = "images/";
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['Image1']['name']);
$_FILES['Image1']['tmp_name'];
$target_path = "images/";
$target_path = $target_path . basename( $_FILES['Image1']['name']);
if(move_uploaded_file($_FILES['Image1']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['Image1']['name'])." has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
But everytime someone uploads the same image name, the image is over-written.
So this is a little problem because users might upload same image names
How can i prevent the script from overwritting old images