Hello Reader's today we discuss about "Check file exists or not in Php".
HTML code :
<!DOCTYPE html>
<html>
<body>
<?php echo $message; ?>
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile[]" type="file" multiple="true" /><br />
<input type="submit" value="Upload File" name="submit" id="submit" />
</form>
</body>
</html>
Php code:
<?php
$target_path = "new/"; // folder name
if(isset($_POST['submit']))
{
$target_path = $target_path . basename( $_FILES['uploadedfile[]']['name']);
if( file_exists($target_path) )
{
$message = "File Allready exists";
}
else
{
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
$message = "File uploaded successfully";}
}
?>
0 Comment(s)