PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Upload Formular überprüfung


chrisse
05.09.2012, 13:11:32
Hallo,

ich habe ein Upload Formular erstellt mit dem man 3 Dateien hochladen soll und die Werte in einer Datenbank gespeichert werden. Vor dem hochladen soll überprüft werden ob der Dateityp erlaubt ist. Das ganze klappt mit einem Dateiupload auch ganz gut nur wenn ich die drei Dateien hochladen will klappt die überprüfung noch nicht.

Das ganze soll so funktionieren das sobald eine Datei nicht erlaubt ist ein Error ausgegeben wird und der Vorgang abgebrochen wird.

Mein Code zur überprüfung sieht wie folgt aus.


$file1_type = $_FILES['userfile1']['type'];
$file2_type = $_FILES['userfile2']['type'];
$file3_type = $_FILES['userfile3']['type'];
if($file1_type != "application/vnd.ms-excel" && $file1_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" && $file1_type != "application/msword" && $file1_type != "application/vnd.openxmlformats-officedocument.wordprocessingml.document" && $file1_type != "application/vnd.ms-powerpoint" && $file1_type != "application/vnd.openxmlformats-officedocument.presentationml.presentation" && $file1_type != "application/pdf" && $file1_type != "image/jpeg" && $file1_type != "image/pjpeg" && $file1_type != "application/zip" && $file1_type != "application/vnd.oasis.opendocument.text" && $file1_type != "application/vnd.stardivision.writer")
{
$err1[] = "Nur folgende Dateien dürfen hochgeladen werden.";
}
if( $file2_type != "application/vnd.ms-excel" && $file2_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" && $file2_type != "application/msword" && $file2_type != "application/vnd.openxmlformats-officedocument.wordprocessingml.document" && $file2_type != "application/vnd.ms-powerpoint" && $file2_type != "application/vnd.openxmlformats-officedocument.presentationml.presentation" && $file2_type != "application/pdf" && $file2_type != "image/jpeg" && $file2_type != "image/pjpeg" && $file2_type != "application/zip" && $file2_type != "application/vnd.oasis.opendocument.text" && $file2_type != "application/vnd.stardivision.writer")
{
$err2[] = "Nur folgende Dateien dürfen hochgeladen werden.";
}
if( $file3_type != "application/vnd.ms-excel" && $file3_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" && $file3_type != "application/msword" && $file3_type != "application/vnd.openxmlformats-officedocument.wordprocessingml.document" && $file3_type != "application/vnd.ms-powerpoint" && $file3_type != "application/vnd.openxmlformats-officedocument.presentationml.presentation" && $file3_type != "application/pdf" && $file3_type != "image/jpeg" && $file3_type != "image/pjpeg" && $file3_type != "application/zip" && $file3_type != "application/vnd.oasis.opendocument.text" && $file3_type != "application/vnd.stardivision.writer")
{
$err3[] = "Nur folgende Dateien dürfen hochgeladen werden.";
}
if(empty($err1) || empty($err2) || empty($err3)) {
mysql_query("insert into ");

move_uploaded_file

{
header('Location: ');
}
}

ich vermute das der fehler im Bereich der if empty abfrage liegt
if(empty($err1) || empty($err2) || empty($err3))

Vielleicht kann mir ja einer bei meinem Problem mit dem Formular helfen. Sie gesagt das ganze funktioniert. wenn nur ein Uploadfeld im Formular ist, einwandfrei.

Gruß
Christoph

vt1816
05.09.2012, 14:32:11
Hallo Christoph,
willkommen hier im Forum.


Ja, Du vermutest richtig. Ist Dir bekannt was der logische Operator "||" bedeutet/macht? Wenn nicht dann schau mal hier (http://www.php.net/manual/en/language.operators.logical.php).
Bitte benutze mal die Suche hier im Forum - das Thema Dateiupload mit Dateiüberprüfung wurde hier schon mehrmals ausführlich diskutiert.