Who can help me with my upload-form?
I want to put this code into the code of my upload-form:
Code: Select all
exec("convert $original_image -thumbnail 250 250 $new_image");
Code: Select all
function checkUpload($myFILE, $file_extensions, $mime_types, $maxsize)
{
$errors = array();
switch ($myFILE['error']){
case 1: $errors[] = " ".ini_get('upload_max_filesize').".";
break;
case 2: $errors[] = " ".$maxsize/(1024*1024)." ";
break;
return $errors;
break;
default : break;
}
// MIME-Type prüfen
if(count($mime_types)!=0 AND !in_array(strtolower($myFILE['type']), $mime_types)){
$fehler = "Falscher MIME-Type (".$myFILE['type'].").<br />".
"Erlaubte Typen sind:<br />\n";
foreach($mime_types as $type)
$fehler .= " - ".$type."\n<br />";
$errors[] = $fehler;
}
if($myFILE['name']=='' OR (count($file_extensions)!=0 AND !in_array(strtolower(getExtension($myFILE['name'])), $file_extensions))){
$fehler = "Falsche Dateiendung (".getExtension($myFILE['name']).").<br />".
"Erlaubte Endungen sind:<br />\n";
foreach($file_extensions as $extension)
$fehler .= " - ".$extension."\n<br />";
$errors[] = $fehler;
}
if($myFILE['size'] > $maxsize){
$errors[] = " (".sprintf('%.2f',$myFILE['size']/(1024*1024))." MB).<br />".
" ".$maxsize/(1024*1024)." MB\n";
}
return $errors;
}
function getExtension ($filename)
{
if(strrpos($filename, '.'))
return substr($filename, strrpos($filename, '.')+1);
return false;
}
function getRandomValue()
{
#return substr(md5(rand(1, 9999)),0,8).substr(time(),-6);
return md5(time());
}
function renameFile ($filename)
{
return getRandomValue().".".getExtension($filename);
}
$maxsize = 2*1024*1024;
$file_extensions = array('jpg', 'jpeg', 'jpe', 'gif', 'png');
$mime_types = array('image/pjpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/x-png');
$ordner = "uploads/big/";
Code: Select all
elseif($_GET['act'] == 'upload'){
$myFILE = $_FILES['photo'];
if(count($errors)){
//
}else {
do {
// move and rename
$neuer_name = renameFile($myFILE['name']);
} while(file_exists($ordner.$neuer_name));
if(@move_uploaded_file($myFILE['tmp_name'], $ordner.$neuer_name)){
// URL
echo $ordner.$neuer_name;
}else{
//
}
}