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.
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ä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ä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>