Hallo,
ich suche schon seit Ewigkeiten, habe bisher aber nichts gefunden, was bei mir auch wirklich funktioniert. Ich habe das mod_easyuploader auf Joomla 1.5.15 und möchte hochgeladene Dateien automatisch von "bild.jpg" in bspw. "07-06-2010-bild.jpg" umbenennen. Ich bin leider noch der totale Anfänger, was PHP betrifft. Hier der Modul-Code:
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
class modEasyFileUploaderHelper
{
public static function getFileToUpload(&$params)
{
$result = "";
//check to see if the upload process has started
if (isset($_FILES[$params->get('efu_variable')]))
{
//now, we're going to check each of the uploaded files
$total = intval($params->get('efu_multiple'));
for ($i = 0; $i < $total; $i++)
{
//so, now, check for any other errors
if ($_FILES[$params->get('efu_variable')]["error"][$i] > 0)
{
//error was found. Show the return code.
$result .= "Return Code: ".$_FILES[$params->get('efu_variable')]["error"][$i]."<br />";
$result .= modEasyFileUploaderHelper::fileUploadErrorMessage($_FILES[$params->get('efu_variable')]["error"][$i]);
}
else
{
//no errors found.
//check to see if the file type is correct
//but first, we have to store the file types in a variable. I was getting an issue with empty()
$filetypes = $params->get('efu_filetypes');
if ($filetypes == "*" || stripos($filetypes, $_FILES[$params->get('efu_variable')]["type"][$i]) !== false)
{
//the file type is permitted
//so, check for the right size
if ($_FILES[$params->get('efu_variable')]["size"][$i] < $params->get('efu_maxsize'))
{
//file is an acceptable size
//check to see if file already exists in the destination folder
if (file_exists(JPATH_SITE.DS.'images'.DS.$params->get('efu_folder').DS.$_FILES[$params->get('efu_variable')]["name"][$i]))
{
//file already exists
//check whether the user wants to replace the file or not.
if ($params->get('efu_replace') == "0" && $_POST["answer"] == "0")
{
//yep, the user wants to replace the file, so just delete the existing file
unlink(JPATH_SITE.DS.'images'.DS.$params->get('efu_folder').DS.$_FILES[$params->get('efu_variable')]["name"][$i]);
$result .= "Die vorherige Datei wurde gelöscht. ";
modEasyFileUploaderHelper::storeUploadedFile($params, $result, $i);
}
else
{
$result .= $_FILES[$params->get('efu_variable')]["name"][$i]." already exists.";
}
}
else
{
modEasyFileUploaderHelper::storeUploadedFile($params, $result, $i);
}
}
else
{
//file is too large
$result .= "Fehler: die Datei ist zu groß. Sie muss kleiner als ".modEasyFileUploaderHelper::sizeToText($params->get('efu_maxsize'))."sein.";
}
}
else
{
//the file type is not permitted
$result .= "Fehler: der Dateityp, ".$_FILES[$params->get('efu_variable')]["type"][$i].", wird nicht unterstützt.";
}
}
$result .= "";
}
}
return $result;
}
private static function storeUploadedFile(&$params, &$result, &$i)
{
//move the file to the destination folder
move_uploaded_file($_FILES[$params->get('efu_variable')]["tmp_name"][$i], JPATH_SITE.DS.'images'.DS.$params->get('efu_folder').DS.$_FILES[$params->get('efu_variable')]["name"][$i]);
//Upload was successful.
$result .= "Der Upload war erfolgreich.<br />";
$result .= "Name: ".$_FILES[$params->get('efu_variable')]["name"][$i]." | ";
$result .= "Typ: ".$_FILES[$params->get('efu_variable')]["type"][$i]." | ";
$result .= "Größe: ".modEasyFileUploaderHelper::sizeToText($_FILES[$params->get('efu_variable')]["size"][$i])."<br />";
$result .= "Temp file: ".$_FILES[$params->get('efu_variable')]["tmp_name"][$i]."<br />";
$result .= "Dateipfad: www.domain.tld/".$params->get('efu_folder').DS.$_FILES[$params->get('efu_variable')]["name"][$i];
}
?>
Danke schon mal im vorraus!