Answer the question
In order to leave comments, you need to log in
Why doesn't it put it in a folder?
Hello! I am creating a personal account on my website, and during registration I ran into a problem that the user's avatar is not entered in the folder.
<form class="form" action="includes/signup.php" method="POST">
<div class="form__group">
<input class="form__control" name="name" type="text" placeholder="Ваше имя">
<input class="form__control" name="login" type="text" placeholder="Логин">
<input class="form__control" name="email" type="email" placeholder="Почта">
<input class="form__control" name="avatar" type="file">
<input class="form__control" name="password" type="password" placeholder="Пароль">
<input class="form__control" name="password_confirm" type="password" placeholder="Повторите пароль">
<div class="btn__sign">
<button class="btn">Зарегистрироваться</button>
<a class="singin" href="auth.php">Вход</a>
</div>
</div>
</form>
<?php
session_start();
require_once "config.php";
$name = $_POST['name'];
$login = $_POST['login'];
$email = $_POST['email'];
$password = $_POST['password'];
$password_confirm = $_POST['password_confirm'];
if($password == $password_confirm) {
$path = 'static/avatar/' . time() . $_FILES['avatar']['name'];
move_uploaded_file($_FILES['avatar']['tmp_name'], '../' . $path);
if (!move_uploaded_file($_FILES['avatar']['tmp_name'], '../' . $path)) {
$_SESSION['message'] = 'Ошибка при загрузке фотографии!';
header('Location: ../register.php');
}
$password = md5($password);
mysqli_query($connection, "INSERT INTO `users` (`id`, `name`, `login`, `email`, `password`, `avatar`) VALUES (NULL, '$name', '$login', '$email', '$password', '$path')");
$_SESSION['message'] = 'Регистрация прошла успешно!';
header('Location: ../auth.php');
} else {
$_SESSION['message'] = 'Пароли не совпадают!';
header('Location: ../register.php');
}
?>
Answer the question
In order to leave comments, you need to log in
Issue resolved.
Solution:
I forgot to write in the form tag
enctype="multipart/form-data"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question