Answer the question
In order to leave comments, you need to log in
How to fix Apache error when uploading a photo to a website?
function isSecurity($avatar){
$name = $avatar["name"];
$type = $avatar["type"];
$size = $avatar["size"];
$blacklist = array(".php", ".html", ".phtml", ".php3", ".php4", ".png");
foreach ($blacklist as $item){
if( preg_match("/$item\$/i", $name) ) return false;
}
if (( $type != "image/jpeg" ) && ( $type != "image/jpg" )) return false;
if ( $size > 5 * 1024 * 1024 ) return false;
return true;
}
function loadAvatar($avatar){
$type = $avatar["type"];
$tmp = $avatar["tmp_name"];
$uploaddir = "http://100master.info/wp-content/themes/malyar-kz/accets/img/master_avatar/";
$name = $_SESSION['logged_user']->user_login.".".substr($type, strlen("image/"));
$uploadfile = $uploaddir.$name;
if(move_uploaded_file($tmp, $uploadfile)){
return true;
}else return false;
}
// Обработка Аватара
if ( isset($_POST["do_edit_master"]) ){
$avatar = $_FILES["avatar"];
// Проверка Аватара
if ( isSecurity($avatar) ) {
// Загрузка аватара
if ( loadAvatar($avatar) ){
$great = "Ошибок нет";
}else $massage = "Ошибка при загрузки автараки.";
}else $massage = "Ошибка при загрузки автараки. Неправильный формат, либо слишком большой размер файла.";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question