Sorry for bringing something up that has probably been asked a million times by now, but I am having some trouble with it and after a couple of hours of searching around and not finding my answer that worked I decided to ask here.
This is the code I am trying to run:
$ext_error = false;
$extensions = array('gif','jpg','jpe','jpeg','png');//Allowed Extensions
$file_ext = explode('.',$_FILES['userfile']['name']);
$file_ext = end($file_ext);
if (!in_array($file_ext, $extensions)){
$ext_error = true;
$file = $_POST['name'];
unlink('img/'.$file);
}
I am trying to make it delete the file uploaded if it turns out to not have the correct file extension.
When I use unlink, 'img/' is a directory inside of the directory where my php file is and I am trying to use $file to find out the name of the file that was just uploaded and had an error of the wrong extension.