potrebuju aby:uploader "poustel" pouze soubory typu .cfg (popripade jeste .rar k tomu-neni podminka);a jeste aby omezil velikost souboru na 50kB.kod ktery zde davam uploaduje obrazky,omezene na velikost 90x90px a puze .jpg a .gif.(databazi a takove veci nereste,nechte vsechno ostatni tak.)diky moc tomu kdo pomuze.
Kód: Vybrat vše
$filepath = "./images/avatars/";
if ($avatar['name'] != "" OR ($_POST['avatar_url'] != "" AND $_POST['avatar_url'] != "http://")) {
if($avatar['name'] != "") {
move_uploaded_file($avatar[tmp_name], $filepath.$avatar[name].".tmp");
} else {
$avatar[name] = strrchr($_POST['avatar_url'],"/");
if(!copy($_POST['avatar_url'],$filepath.$avatar[name].".tmp")) {
$error = "can not copy file from server";
die('ERROR: '.$error.'<br><br><input type="button" class="button" onClick="javascript:history.back()" value="Back">');
}
}
@chmod($filepath.$avatar[name].".tmp", 0755);
$info = getimagesize($filepath.$avatar[name].".tmp");
if($info[0] < 91 && $info[1] < 91) {
if($info[2] == 2) {
$pic=$id.'.jpg';
if(file_exists($filepath.$pic)) @unlink($filepath.$pic);
if(file_exists($filepath.$id.'.gif')) @unlink($filepath.$id.'.gif');
rename($filepath.$avatar[name].".tmp", $filepath.$pic);
safe_query("UPDATE ".PREFIX."user SET avatar='$pic' WHERE userID='$id' ");
}
elseif($info[2] == 1) {
$pic=$id.'.gif';
if(file_exists($filepath.$pic)) @unlink($filepath.$pic);
if(file_exists($filepath.$id.'.jpg')) @unlink($filepath.$id.'.jpg');
rename($filepath.$avatar[name].".tmp", $filepath.$pic);
safe_query("UPDATE ".PREFIX."user SET avatar='$pic' WHERE userID='$id' ");
}
else {
if(unlink($filepath.$avatar[name].".tmp")) {
$error = "invalid picture-format (allowed: gif or jpg)";
die('ERROR: '.$error.'<br><br><input type="button" class="button" onClick="javascript:history.back()" value="Back">');
} else {
$error = "upload failed";
die('ERROR: '.$error.'<br><br><input type="button" class="button" onClick="javascript:history.back()" value="Back">');
}
}
}
else {
@unlink($filepath.$avatar[name].".tmp");
$error = "picture is to big max 90/90px";
die('ERROR: '.$error.'<br><br><input type="button" class="button" onClick="javascript:history.back()" value="Back">');
}
}
