Tak kod nic moc ale tvoja chyba spociva v tom, ze si nezratas kolko inputov bolo vyplnenych z tych styroch. Program ti potom robi to, ze sa snazi ulozit aj prazdny input a ten samozrejme nieje formatu JPG
a tak da exit. Najlepsie spravis ak si spocitas kolko inputov bolo vyplnenych, napriklad staci ked spravis
nieco taketo (robim to len tak, tak si to potom uprav)
Kód:
<?php
echo "<form name=\"image_upload\" enctype=\"multipart/form-data\" method=\"post\" action=\"$PHP_SELF\">\n";
$fields = 4;
for($x=0;$x<$fields;$x++){
echo "<input name=\"image$x\" type=\"file\" id=\"image$x\"><br><br>\n";
}
echo "<input type=\"submit\" name=\"submit\" value=\"Nahraj\">\n";
echo "</form>";
if($_POST['submit'])
{
$count = 0;
for($x=0;$x<$fields;$x++){
$file_name = $_FILES['image'. $x]['name'];
if(!($file_name == ""))
$count += 1;
}
for($x=0;$x<$count;$x++){
$file_name = $_FILES['image'. $x]['name'];
$uploads = 'data';
$maxwidth = 1000;
$maxheight = 500;
$max_filesize = 202400;
$types_array = array('image/jpg','image/jpeg','image/JPG','image/JPEG');
$imagesize = getimagesize($_FILES['image'. $x]['tmp_name']);
$imagewidth = $imagesize[0];
$imageheight = $imagesize[1];
if($imagewidth > $maxwidth || $imageheight > $maxheight)
{
echo "<font color=\"red\">Chyba: Povolené sú len obrázky s veľkosťou ".$maxwidth." x ".$maxheight." px.</font><br />";
exit;
}
else if($_FILES['image'. $x]['size'] > $max_filesize)
{
echo "<font color=\"red\">Chyba: Max. veľkosť obrázku je ".$max_filesize_kb." kb.</font><br />";
exit;
}
else if(!(in_array($_FILES['image'. $x]['type'], $types_array)))
{
echo "<font color=\"red\">Chyba: Povolené sú len obrázky z koncovkami <strong>*jpg</strong> a <strong>*jpeg</strong></font><br />";
exit;
}else{
$copy = copy($_FILES['image'. $x]['tmp_name'],$uploads.'/'.$file_name);
}
if($copy){
echo "<font color=\"green\">Obrázky boli úspešne nahraté na server! Ďakujeme ...</font><br />";
}else{
echo "<font color=\"red\">Obrázok <strong>$file_name</strong> sa nepodaril nahrať na server!</font><br />";
}
}
}
?>