K
K
Konstantin Lavrovsky2019-03-11 16:34:21
PHP
Konstantin Lavrovsky, 2019-03-11 16:34:21

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 = "Ошибка при загрузки автараки. Неправильный формат, либо слишком большой размер файла.";
}

On the form enctype="multipart/form-data" stands.
Rights to all directories and files in the root of the site 755, this should not be a problem.
When I upload a photo, I get the error "Error when uploading avatars", that is, it fits in size and format.
Site on WP, not sure if the path to the folder ($uploaddir) is written correctly.
5c8662e229983957890719.png
The page is in malyar-kz.
There is an error in the server logs, namely the problem with APACHE, I don’t know how to solve it, it swears at the line with if(move_uploaded_file($tmp, $uploadfile)).
5c866359cf78c418673728.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2019-03-11
@s1mypj

The directory for downloading files must be specified not as a link, but as a path in the file system
or relative to the script file
number ../ please specify

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question