habe hier ein php-Script zum Upload von Dateien. Funktioniert soweit alles, jetzt hab ich im nachhinein noch einen Passwortschutz (rot gekennzeichnet) eingebaut, doch leider geht jetzt garnix mehr. Muss die if-Abfrage an eine andere Stelle?
<?php
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "aktuell/";
$upload_url = $url_dir."aktuell/";
$message ="";
[COLOR=red]if($password == "test") {[/COLOR]
if (!is_dir("aktuell")) {
die ("Verzeichnis existiert nicht");
}
if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "Datei auswaehlen und updaten.";
}
print $message;
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;
//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
//File Size Check
else if ( $file_size > 500000) {
$message = "The file size is over 500K.";
return $message;
}
//File Type Check
else if ( $file_type != "text/plain" ) {
$message = "Sorry, You cannot upload any script file" ;
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"File url <a href=$file_url>$file_url</a>" :
"Somthing is wrong with uploading a file.";
return $message;
}
[COLOR=red]}[/COLOR]
?>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
Datei aktuell.txt auswaehlen: <input type="file" id="userfile" name="userfile">
<br><input type="submit" name="upload" value="Upload">
[COLOR=red]<br><input type="password" name="password" size="25">[/COLOR]
<?php
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "aktuell/";
$upload_url = $url_dir."aktuell/";
$message ="";
[COLOR=red]if($password == "test") {[/COLOR]
if (!is_dir("aktuell")) {
die ("Verzeichnis existiert nicht");
}
if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "Datei auswaehlen und updaten.";
}
print $message;
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;
//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
//File Size Check
else if ( $file_size > 500000) {
$message = "The file size is over 500K.";
return $message;
}
//File Type Check
else if ( $file_type != "text/plain" ) {
$message = "Sorry, You cannot upload any script file" ;
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"File url <a href=$file_url>$file_url</a>" :
"Somthing is wrong with uploading a file.";
return $message;
}
[COLOR=red]}[/COLOR]
?>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
Datei aktuell.txt auswaehlen: <input type="file" id="userfile" name="userfile">
<br><input type="submit" name="upload" value="Upload">
[COLOR=red]<br><input type="password" name="password" size="25">[/COLOR]
Kommentar