language = "en"; // choice of en, nl, es
$this->rename_file = false;
$this->ext_string = "";
}
// some error (HTTP)reporting, change the messages or remove options if you like.
function error_text($err_num) {
switch ($this->language) {
case "nl":
$error[0] = "Foto succesvol kopieert.";
$error[1] = "Het bestand is te groot, controlleer de max. toegelaten bestandsgrootte.";
$error[2] = "Het bestand is te groot, controlleer de max. toegelaten bestandsgrootte.";
$error[3] = "Fout bij het uploaden, probeer het nog een keer.";
$error[4] = "Fout bij het uploaden, probeer het nog een keer.";
$error[10] = "Selecteer een bestand.";
$error[11] = "Het zijn alleen bestanden van dit type toegestaan: ".$this->ext_string."";
$error[12] = "Sorry, de bestandsnaam bevat tekens die niet zijn toegestaan. Gebruik alleen nummer, letters en het underscore teken. Een geldige naam eindigt met een punt en de extensie.";
$error[13] = "De bestandsnaam is te lang, het maximum is: ".$this->max_length_filename." teken.";
$error[14] = "Sorry, het opgegeven directory bestaat niet!";
$error[15] = "Uploading ".$this->the_file."...Fout! Sorry, er is al een bestand met deze naam aanwezig.";
break;
case "de":
$error[0] = "Die Datei: ".$this->the_file." wurde hochgeladen!";
$error[1] = "Die hochzuladende Datei ist größer als der Wert in der Server-Konfiguration!";
$error[2] = "Die hochzuladende Datei ist größer als der Wert in der Klassen-Konfiguration!";
$error[3] = "Die hochzuladende Datei wurde nur teilweise übertragen";
$error[4] = "Es wurde keine Datei hochgeladen";
$error[10] = "Wählen Sie eine Datei aus!.";
$error[11] = "Es sind nur Dateien mit folgenden Endungen erlaubt: ".$this->ext_string."";
$error[12] = "Der Dateiname enthält ungültige Zeichen. Benutzen Sie nur alphanumerische Zeichen für den Dateinamen mit Unterstrich.Ein gültiger Dateiname endet mit einem Punkt, gefolgt von der Endung.";
$error[13] = "Der Dateiname überschreitet die maximale Anzahl von ".$this->max_length_filename." Zeichen.";
$error[14] = "Das Upload-Verzeichnis existiert nicht!";
$error[15] = "Upload ".$this->the_file."...Fehler! Eine Datei mit gleichem Dateinamen existiert bereits.";
break;
case "es":
$error[0] = "El fichero: ".$this->the_file." se ha cargado correctamente!";
$error[1] = "El fichero a cargar excede del tamaño máximo de la directiva en la configuración del servidor.";
$error[2] = "El fichero a cargar excede del tamaño máximo de la directiva especificada en el formulario html.";
$error[3] = "El fichero a cargar solo lo ha sido parcialmente.";
$error[4] = "El fichero no ha sido cargado.";
$error[10] = "Por favor seleccione un fichero a cargar.";
$error[11] = "Solo ficheros con las siguientes extensiones están permitidos: ".$this->ext_string."";
$error[12] = "Lo siento, el nombre del fichero contiene carácteres invalidos. Use solo carácteres alfanuméricos y separe (si es necesario) con un subrayado. Un nombre de fichero correcto acaba con un punto seguido de la extensión.";
$error[13] = "El nombre de fichero excede de la longitud máxima de ".$this->max_length_filename." carácteres.";
$error[14] = "¡Lo siento, el directorio de destino no existe!";
$error[15] = "Cargando ".$this->the_file."...Error! lo siento, un fichero con el mismo nombre ya existe.";
break;
default:
// start http errors
$error[0] = "File: ".$this->the_file." successfully uploaded!";
$error[1] = "The uploaded file exceeds the max. upload filesize directive in the server configuration.";
$error[2] = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.";
$error[3] = "The uploaded file was only partially uploaded";
$error[4] = "No file was uploaded";
// end http errors
$error[10] = "Please select a file for upload.";
$error[11] = "Only files with the following extensions are allowed: ".$this->ext_string."";
$error[12] = "Sorry, the filename contains invalid characters. Use only alphanumerical chars and separate parts of the name (if needed) with an underscore. A valid filename ends with one dot followed by the extension.";
$error[13] = "The filename exceeds the maximum length of ".$this->max_length_filename." characters.";
$error[14] = "Sorry, the upload directory doesn't exist!";
$error[15] = "Uploading ".$this->the_file."...Error! Sorry, a file with this name already exitst.";
}
return $error[$err_num];
}
function show_error_string() {
$msg_string = "";
foreach ($this->message as $value) {
$msg_string .= $value."
\n";
}
return $msg_string;
}
function upload() {
if ($this->check_file_name()) {
if ($this->validateExtension()) {
if (is_uploaded_file($this->the_temp_file)) {
// this check/conversion is used for unique filenames
$this->file_copy = ($this->rename_file) ? strtotime("now").$this->get_extension($this->the_file) : $this->the_file;
if ($this->move_upload($this->the_temp_file, $this->file_copy)) {
$this->message[] = $this->error_text($this->http_error);
return true;
}
} else {
$this->message[] = $this->error_text($this->http_error);
return false;
}
} else {
$this->show_extensions();
$this->message[] = $this->error_text(11);
return false;
}
} else {
return false;
}
}
function check_file_name() {
if ($this->the_file != "") {
if (strlen($this->the_file) > $this->max_length_filename) {
$this->message[] = $this->error_text(13);
return false;
} else {
if ($this->do_filename_check == "y") {
if (ereg("^[a-zA-z0-9_]*\.[a-zA-az]{3,4}$", $this->the_file)) {
return true;
} else {
$this->message[] = $this->error_text(12);
return false;
}
} else {
return true;
}
}
} else {
$this->message[] = $this->error_text(10);
return false;
}
}
function get_extension($from_file) {
$ext = strtolower(strrchr($from_file,"."));
return $ext;
}
function validateExtension() {
$extension = $this->get_extension($this->the_file);
$ext_array = $this->extensions;
if (in_array($extension, $ext_array)) {
return true;
} else {
return false;
}
}
// this method is only used for detailed error reporting
function show_extensions() {
$this->ext_string = implode(" ", $this->extensions);
}
function move_upload($tmp_file, $new_file) {
umask(0);
if ($this->existing_file()) {
$newfile = $this->upload_dir.$new_file;
if ($this->check_dir()) {
if (move_uploaded_file($tmp_file, $newfile)) {
if ($this->replace == "y") {
system("chmod 0777 $newfile");
} else {
system("chmod 0755 $newfile");
}
return true;
} else {
return false;
}
} else {
$this->message[] = $this->error_text(14);
return false;
}
} else {
$this->message[] = $this->error_text(15);
return false;
}
}
function check_dir() {
if (!is_dir($this->upload_dir)) {
return false;
} else {
return true;
}
}
function existing_file() {
if ($this->replace == "y") {
return true;
} else {
if (file_exists($this->upload_dir.$this->the_file)) {
return false;
} else {
return true;
}
}
}
}
?>