Ragazi, come da titolo, ho un problema in un form PHP.
In poche parole, ho inserito un messaggio di errore dentro ad una condizione e ogni volta che lascio vuoto mi mostra sempre l'errore. Ecco il codice:
Codice PHP:
if(isset($_POST['send_mod']))
{
$band_id = isset($bands_edit);
$band_name = htmlspecialchars(trim($_POST['name']));
$band_letter = ((strpos(strtolower($band_name), 'the ') === 0) ? substr((substr($band_name, 4, -1) . ', ' . substr($band_name, 0, 4)),0,1) : substr($band_name, 0, 1));
$band_genre = '';
for ($i=0; $i < sizeof($HTTP_POST_VARS['genre']); $i++)
{
$band_genre .= $HTTP_POST_VARS['genre'][$i]." ";
};
$band_label = $_POST['label'];
$band_city_formed = htmlspecialchars(trim($_POST['city']));
$band_date_formed = htmlspecialchars(trim($_POST['date']));
$band_name_album = htmlspecialchars(trim($_POST['name_album']));
$band_date_album = htmlspecialchars(trim($_POST['date_album']));
$band_website = str_replace('http://', '', htmlspecialchars(trim($_POST['website'])));
$band_myspace = str_replace('http://', '', htmlspecialchars(trim($_POST['myspace'])));
for($i = 1; $i <= 10; $i++)
{
$band_member_name = $band_names['name'][$i] = $_POST['name_' . $i];
$band_member_part = $band_parts['part'][$i] = $_POST['part_' . $i];
$band_delete_member[$i] = (isset($_POST['delete_member_' . $i])) ? true : false;
}
$band_bio = htmlspecialchars(trim($_POST['bio']));
if(isset($_FILES['band_logo']))
{
$upload_dir = IP_ROOT_PATH . 'images/bands/' . strtolower($band_letter) . '/';
$filetypes = 'jpg,gif,png';
$maxsize = (1600 * 1200);
$filename = strtolower($_FILES['band_logo']['name']);
$types = explode(',', $filetypes);
$file = explode('.', $filename);
$extension = $file[count($file) - 1];
$filename = substr($filename, 0, strlen($filename) - strlen($extension) - 1);
if(!in_array($extension, $types))
{
message_die(GENERAL_MESSAGE, $lang['Upload_File_Type_Allowed'] . ': ' . str_replace(',', ', ', $filetypes) . '.');
}
if (is_dir($upload_dir))
{
$filename = make_url_friendly($band_name);
}
else
{
$dir_creation = mkdir($upload_dir, 0777);
if ($dir_creation)
{
$filename = make_url_friendly($band_name);
}
else
{
$filename = make_url_friendly($band_name);
}
}
$filename_tmp = $_FILES['band_logo']['tmp_name'];
$file_size = $_FILES['band_logo']['size'];
if($file_size > $maxsize)
{
message_die(GENERAL_MESSAGE, $lang['Upload_File_Too_Big'] . ' ' . ($maxsize / 1000) . 'KB');
}
if(is_uploaded_file($filename_tmp))
{
move_uploaded_file($filename_tmp, $upload_dir . $filename . '.' . $extension);
}
else
{
message_die(GENERAL_MESSAGE, 'Impossibile caricare immagine in ' . $upload_dir);
}
$pic_size = @getimagesize($upload_dir . $filename . '.' . $extension);
$logo_width = $pic_size[0];
$logo_height = $pic_size[1];
if($pic_size == false)
{
@unlink($upload_dir . $filename . '.' . $extension);
message_die(GENERAL_MESSAGE, $lang['Upload_File_Type_Allowed'] . ': ' . str_replace(',', ', ', $filetypes) . '.');
}
}
}
La riga "incriminata" è questa:
Codice PHP:
if(!in_array($extension, $types))
{
message_die(GENERAL_MESSAGE, $lang['Upload_File_Type_Allowed'] . ': ' . str_replace(',', ', ', $filetypes) . '.');
}
Questo messaggio viene mostrato se non inserisco un file nell'input, anche se la condizione if(isset($_FILES['band_logo'])) è false.
Dato che si trova in questa condizione, come è possibile che venga elaborata?
Grazie in anticipo ad eventuali risposte