• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

zip upload und entpacken -> erkennt keine zip / zip inhalt überpfüfen

Rocky007

Mitglied
Hallo,

ich bin momentan dabei ein uploadscript für zip dateien zu schreiben.
Nun möchte ich jedoch, dass nur zip dateien hochgeladen werden können.
Leider lässt er mir garkeine dateiuploads durch...

Nun möchte ich noch, dass das script überpfüft, dass in dem zip-File nur "jpg"-Dateien enthalten sind, andernfalls soll es gar nicht erst entpacken.
hättet ihr dafür ein script?

Hoffe ihr könnt mir helfen.

PHP:
< ?php

if(isset($_GET["upload"])){

if($_GET["upload"] == "yes"){

    $password = $_POST['password'];

    if($password != "test"){

        echo "<h2>Falsches Passwort</h2>";

    }

    else {

if($_FILES["zip_file"]["name"]) {

    $dateiname = $_FILES["zip_file"]["name"];

    $quelldatei = $_FILES["zip_file"]["tmp_name"];

    $typ = $_FILES["zip_file"]["type"];

    $erlaubte_typen = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');

    $okay = null;

 

    $name = explode(".", $dateiname);

    foreach($erlaubte_typen as $mime_type) {

        if($mime_type == $typ) {

            $okay = true;

            break;

        }

        else {

            $okay = false;

            break;

        }

    }

    

        $continue = strtolower($name[1]) == 'zip' ? true : false;

        if(!$continue) {

            $nachricht = "Du l&auml;dst keine \".zip\"Datei hoch. Bitte versuche es nocheinmal.";

        }

 

        if($okay == true) {

 

        $ziel_pfad = "./".$dateiname;

        if(move_uploaded_file($quelldatei, $ziel_pfad)) {

            $zip = new ZipArchive();

            $x = $zip->open($ziel_pfad);

            if ($x === true) {

                $zip->extractTo("./");

                $zip->close();


                unlink($ziel_pfad);

            }

            $nachricht = "Die \".zip\"Datei wurde hochgeladen und entpackt.";

        } else {    

            $nachricht = "Es gab einen Fehler beim Upload. Bitte versuche es nocheinmal.";

        }

        }

        else {

            $nachricht = "Du l&auml;dst keine \".zip\"Datei hoch. Bitte versuche es nocheinmal.";

        }

    }

}

}

}

?>


< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

< html xmlns="http://www.w3.org/1999/xhtml">

< head>

< meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

< title>Scan Upload</title>

< /head>

 

< body>

< font color='red' style='bold'><?php if($nachricht) echo "<p>$nachricht</p>"; ?></font>

< form enctype="multipart/form-data" method="post" action="upload.php?upload=yes">

< label>Choose a zip file to upload: <input type="file" name="zip_file" /></label>

< br \>

Passwort: <input name="password" type="password" size="11" maxlength="10">

< br\ >

< input type="submit" name="submit" value="Upload" />

< /form>

< /body>

< /html>
 
Werbung:
Deine Schleife ist falsch aufgebaut - zudem würde sich hier in_array() besser anbieten.

Versuch es mal so:
PHP:
<?php
if(isset($_GET["upload"])) {
    if($_GET["upload"] == "yes") {
        $password = $_POST['password'];
        if($password != "test"){
            echo "<h2>Falsches Passwort</h2>";
        } else {
            if($_FILES["zip_file"]["name"]) {
                $dateiname = $_FILES["zip_file"]["name"];
                $quelldatei = $_FILES["zip_file"]["tmp_name"];
                $typ = $_FILES["zip_file"]["type"];
                $erlaubte_typen = array(                    
                    'application/zip',                     
                    'application/x-zip-compressed',                     
                    'multipart/x-zip',                     
                    'application/x-compressed'                
                );
                $okay = false;                
                if (in_array($typ, $erlaubte_typen)) {                    
                    $okay = true;                  
                } 
                if($okay == true) {                     $ziel_pfad = "./".$dateiname;
                    if(move_uploaded_file($quelldatei, $ziel_pfad)) {
                        $zip = new ZipArchive();
                        $x = $zip->open($ziel_pfad);
                        if ($x === true) {
                            $zip->extractTo("./");
                            $zip->close();

                            unlink($ziel_pfad);
                        }
                        $nachricht = "Die \".zip\"Datei wurde hochgeladen und entpackt.";
                    } else {    
                        $nachricht = "Es gab einen Fehler beim Upload. Bitte versuche es nocheinmal.";
                    }
                } else {
                    $nachricht = "Du l&auml;dst keine \".zip\"Datei hoch. Bitte versuche es nocheinmal.";
                }
            }
        }
    }
}
?>
 
Soweit läufts perfekt danke dir...
Das war teil 1 was zu tun war...
Nun möchte ich noch, dass das script überpfüft, dass in dem zip-File nur "jpg"-Dateien enthalten sind, andernfalls soll es gar nicht erst entpacken.
Die Struktur sieht dabei folgendermaßen aus:
ZIP
-Ordner1
-Datei1.jpg
-Ordner2
-Datei1.jpg
-Ordner1
-UnterOrdner1
-Datei1.jpg
 
Werbung:
Das entpacken wird dir kaum erspart bleiben. Ich würde die ZIP in einem temporären Verzeichnis entpacken und alle JPG-Dateien ins richtige Verzeichnis verschieben.
 
Zurück
Oben