Jestem początkującym uzytkownikiem PHP. Jestem w trakcie tworzenia malego systemu,w ktorym uzytkownik (m. in) bedzie mial mozliwosc uploadowania swojego avatara w formacie jpg. Problem polegana tym ,ze chcialem aby mial rowniez mozliwosc opuszczenia tego kroku (czyli pozostawienia pustego formularza) i przejscia dalej. Nie wiem jak mam sformulowac poprawny warunek. Jak narazie walidacja pliku wyglada tak:
CODE
if ($filesize1 > 200) {
$error = "Your avatar can`t be bigger than 200 KB<br/><a href='java script:java script:history.go(-1)'>Back</a>";
} elseif ($_FILES['avatar']['type']!= "image/pjpeg") {
$error = "Your avatar has to be saved as JPEG file !<br/><a href='java script:java script:history.go(-1)'>Back</a>";
} elseif (file_exists("avatars/".$_FILES['avatar']['name'])) {
$error = "This file already exists in our database !<br/><a href='java script:java script:history.go(-1)'>Back</a>";
} else {
move_uploaded_file ($_FILES['avatar']['tmp_name'], "avatars/".$_FILES['avatar']['name']);
list($imgwidth, $imgheight) = getimagesize("avatars/".$_FILES['avatar']['name']);
if ($imgwidth > 150 || $imgheight >150) {
$error = "Your avatar can`t be bigger than 150x150 px.<br/><a href='java script:java script:history.go(-1)'>Back</a>";
unlink("avatars/".$_FILES['avatar']['name']);
} else {
$result = mysql_query($filequery, $dblink);
$result2 = mysql_query($descriptionquery, $dblink);
$positive = "You have been succesfully registered. "
."You will be redirected to our homepage in 5 seconds !";
};
};
$error = "Your avatar can`t be bigger than 200 KB<br/><a href='java script:java script:history.go(-1)'>Back</a>";
} elseif ($_FILES['avatar']['type']!= "image/pjpeg") {
$error = "Your avatar has to be saved as JPEG file !<br/><a href='java script:java script:history.go(-1)'>Back</a>";
} elseif (file_exists("avatars/".$_FILES['avatar']['name'])) {
$error = "This file already exists in our database !<br/><a href='java script:java script:history.go(-1)'>Back</a>";
} else {
move_uploaded_file ($_FILES['avatar']['tmp_name'], "avatars/".$_FILES['avatar']['name']);
list($imgwidth, $imgheight) = getimagesize("avatars/".$_FILES['avatar']['name']);
if ($imgwidth > 150 || $imgheight >150) {
$error = "Your avatar can`t be bigger than 150x150 px.<br/><a href='java script:java script:history.go(-1)'>Back</a>";
unlink("avatars/".$_FILES['avatar']['name']);
} else {
$result = mysql_query($filequery, $dblink);
$result2 = mysql_query($descriptionquery, $dblink);
$positive = "You have been succesfully registered. "
."You will be redirected to our homepage in 5 seconds !";
};
};
Naturalnie problem lezy tutaj:
Kod
....} elseif ($_FILES['avatar']['type']!= "image/pjpeg") {....
Jak mogę przekonstrulowac ten warunek aby brzmiał: "Jeżeli typ pliku nie jest równy image/jpg z wykluczeniem ""(puste pole) to kontynuluj ..." Lub co wogole moge zrobic aby wykluczyc z powyzszego warunku branie pod uwage "" czyli pustego atrybutu.
Przepraszam jezeli nie wyrazam sie jasno. Pierwszy raz pisze na forum w takiej sprawie

Pozdrawiam :-)