Atm you're doing:
PHP Code:
if($file['type'] == $allowed)
So you're actually comparing it to the $allowed array as a whole, and not checking whether the file type is actually one of the values in the allowed array. Change your code to:
PHP Code:
define("MAX_FILE_SIZE", 307200); // This is the file size in bytes
$allowed = array('image/png', 'image/jpeg', 'image/bmp', 'image/gif', 'image/pjpeg');
foreach($_FILES as $file) {
if($file['size'] > MAX_FILE_SIZE) {
$error .= "<li>Nuotraukos dydis viršija 0.3mb!</li>";
} else {
if(in_array($file['type'], $allowed)) {
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
$fileName = basename($_FILES['uploadedfile']['name']);}
} else {
$tt = $file['type'];
$error .= "<li>Nuotrauka yra neleistino $tt formato. Leistini: .png .jpg .gif .bmp</li>";
}
}
}
Sorry about the formatting
Bookmarks