I know this must be a repeated question but I have a different requirement here. What I want is when a user clicks on the Upload button, the dialog-box that appears only allows the user to upload the PDF file type only and nothing else.
What I've seen so far is once the user uploads a file, then there is a check done for file-type. I don't want to allow the user to upload files other than the pdf.
<?php
$allowedExts = array("pdf");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if (($_FILES["file"]["type"] == "application/pdf") && ($_FILES["file"]["size"] < 200000) && in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("doc_libraray/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
header('Location: '.site_url());
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"doc_libraray/" . $_FILES["file"]["name"]);
echo "Stored in: " . "doc_libraray/" . $_FILES["file"]["name"];
header('Location: '.$newURL);
}
}
}
else
{
echo "Invalid file";
}
?>
Please suggest a way to achieve it!