I have a page that edits some text fields and also a current file stored on the server. If the user leaves the file input blank, it automatically deletes the file already stored on the server. I would like to prevent this and if user leaves it blank the file doesn't delete Here is my php script:
$allowedExtsf = array("pdf");
$tempf = explode(".", $_FILES["flyer"]["name"]);
$extensionf = end($tempf);
if (($_FILES["flyer"]["type"] == "application/pdf") && ($_FILES["flyer"]["size"] < 524288000) && in_array($extensionf, $allowedExtsf))
{
if ($_FILES["flyer"]["error"] > 0)
{
echo "Return Code: " . $_FILES["flyer"]["error"] . "<br>";
}
else
{
if (file_exists("../flyers/" . $_FILES["flyer"]["name"]))
{
unlink("../flyers/" . $_FILES["flyer"]["name"]);
}
move_uploaded_file($_FILES["flyer"]["tmp_name"],"../flyers/" . $_FILES["flyer"]["name"]);
$ad_link="http://www.website.com/flyers/" . $_FILES["flyer"]["name"];
}
}