Mailinglisten-Archive |
Ole,
Besten Dank für die Informationen.
Falls jemand nicht die PEAR Upload Klasse verwenden möchte, habe ich meine
Lösung auch noch hingeschrieben. Kritik und Vorschläge sind erwünscht!
>From: "Gerd Terlutter" <gerd at MplusB.de> wrote:
>
>auf pear gibt es HTTP_Upload[0], alternativ auch HTML_QuickForm[1].
>beide bieten dir die möglichkeit von upload, habe bisher aber erst einen
>upload selber realisiert und mich nicht in deren funktionen
>eingearbeitet. fuer ein aktuelles projekt verwende ich gerade [1], bin
>aber noch bei der basisfunktionalitaet.
>
>Gruss,
>Gerd
>[0]http://pear.php.net/package/HTTP_Upload
>[1]http://pear.php.net/package/HTML_QuickForm
>
/**
* uploads files
*
* @global array $_CONFIG
* @global array $_FILES
* @return boolean false if error
*/
function uploader()
{
global $_CONFIG;
$path = $_CONFIG['documentRoot'].$_CONFIG['coreContentImageDir'];
if(isset($_FILES) AND is_array($_FILES))
{
$filesKeys = array_keys($_FILES);
foreach ($filesKeys as $fileName)
{
$fname = cleanFileName($_FILES[$fileName]['name']);
$fsize = $_FILES[$fileName]['size'];
$ftemp = $_FILES[$fileName]['tmp_name'];
if(!empty($ftemp))
{
while(file_exists($path.$fname))
{
$rand =time();
$fname = $rand.$fname;
}
if(!eregi(".php",$fname))
{
if(!move_uploaded_file($ftemp,$path.$fname))
{
return false;
}
}
}
}
}
return true;
}
/**
* Format a file name to be safe
*
* @param string $file The string file name
* @param int $maxlen Maximun permited string lenght
* @return string Formatted file name
*/
function cleanFileName($name, $maxlen=250)
{
$noalpha = 'áéíóúàèìòùäëïöüÁÉÍÓÚÀÈÌÒÙÄËÏÖÜâêîôûÂÊÎÔÛñçÇ@';
$alpha = 'aeiouaeiouaeiouAEIOUAEIOUAEIOUaeiouAEIOUncCa';
$name = substr ($name, 0, $maxlen);
$name = strtr ($name, $noalpha, $alpha);
$mixChars = array('Þ' => 'th', 'þ' => 'th', 'Ð' => 'dh', 'ð' => 'dh',
'ß' => 'ss', 'O' => 'oe', 'o' => 'oe', 'Æ' => 'ae',
'æ' => 'ae', '$' => 's', '¥' => 'y');
$name = strtr($name, $mixChars);
// not permitted chars are replaced with "_"
return ereg_replace ('[^a-zA-Z0-9,._\+\()\-]', '_', $name);
}
Gruss
Ivan
php::bar PHP Wiki - Listenarchive