I'm new to programming in PHP, and I'm trying to make a multiple file upload script, but I don't know how to check if the uploading files already exist! How can I do that? Can you help me? This is my code:
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload">
</form>
foreach($_FILES['files']['name'] as $i => $name) {
$name = $_FILES['files']['name'][$i];
$size = $_FILES['files']['size'][$i];
$type = $_FILES['files']['type'][$i];
$tmp = $_FILES['files']['tmp_name'][$i];
$explode = explode('.', $name);
$ext = end($explode);
$path = 'uploads/';
$path = $path . basename( $explode[0] . time() .'.'. $ext);
$errors = array();
if(empty($_FILES['files']['tmp_name'][$i])) {
$errors[] = 'Please choose at least 1 file to be uploaded.';
}
if(empty($errors)) {
if(!file_exists('uploads')) {
mkdir('uploads', 0777);
}
if(move_uploaded_file($tmp, $path)) {
echo '<p>The file <b>'.$name.'</b> successfully uploaded</p>';
}else {
echo 'Something went wrong while uploading the file <b>'.$name.'</b>';
}
}else {
foreach($errors as $error) {
echo '<p>'.$error.'<p>';
}
}
}
?>
</div>