I want a user can only upload DOC and XLS file. But if the file is an image, the image file is displayed in the web page (upload.php) and then deleted automatically from the server.
Here is my piece code:
if (file_exists("uploads/" . $_FILES["file"]["name"])) {
echo "<br>File already exists!.<br>";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
if (($_FILES["file"]["type"] == "image/gif" )
||($_FILES["file"]["type"] == "image/jpeg" )
||($_FILES["file"]["type"] == "image/jpg" )
||($_FILES["file"]["type"] == "image/png" )
&& in_array($extension, $allowedExts)){
echo '<br><br><img src="uploads/'.rawurlencode($_FILES["file"]["name"]).'" style="height:30%;"><br>';
} else {
echo '<br><br><a href="uploads/'.rawurlencode($_FILES["file"]["name"]).'"><p><strong>Download File</strong></p></a><br>';
}
}