How to test if a user has uploaded a file ?
Posted
by Tristan
on Stack Overflow
See other posts from Stack Overflow
or by Tristan
Published on 2010-06-02T13:33:21Z
Indexed on
2010/06/02
13:33 UTC
Read the original article
Hit count: 215
Hello,
on a page, i have :
if (!empty($_FILES['logo']['name'])) {
$dossier = 'upload/';
$fichier = basename($_FILES['logo']['name']);
$taille_maxi = 100000;
$taille = filesize($_FILES['logo']['tmp_name']);
$extensions = array('.png', '.jpg', '.jpeg');
$extension = strrchr($_FILES['logo']['name'], '.');
//Début des vérifications de sécurité...
if(!in_array($extension, $extensions))
{
$erreur = 'ERROR you must upload the right type';
}
if($taille>$taille_maxi)
{
$erreur = 'too heavy';
}
if(!empty($erreur))
{
.......................
}
The problem is, if the users wants to edit information WITHOUT uploading a LOGO, it raises an error : 'error you must upload the right type'
So, if a user didn't put anything in the inputbox in order to upload it, i don't want to enter in these conditions test.
i tested :
if (!empty($_FILES['logo']['name'])
and if (isset($_FILES['logo']['name'])
but both doesn't seems to work.
Any ideas?
thanks.
© Stack Overflow or respective owner