S
S
Stas Karpik2020-04-17 09:56:01
PHP
Stas Karpik, 2020-04-17 09:56:01

How to make check with $_FILES condition work?

Hello, I'm asking for help.
There is a form

<form method="GET" enctype="multipart/form-data">
                <input name="messimg" type="file" id="messimg"/>
                <h3><textarea name="message" id="textarea"></textarea><input type="submit" name="button" id="button" value=""/></h3>
            </form>

php:
if($_FILES['messimg']['name']) {
    $path = "chat_images/" . time() . $_FILES['messimg']['name'];
    move_uploaded_file($_FILES['messimg']['tmp_name'], "../" . $path);
}

$today = date("F j, Y, g:i a");

//вставляем значения
if($message && $path){
    $stm = $dbh->prepare("INSERT INTO `messages` (`author`, `message`, `time`, `avatar`, `img`) VALUES ('$author', '$message', '$today', '$avatar', '$path')");
    $stm->execute();
}

When selecting an image in the form and entering a message, the selected file is still not added to the chat_images folder. What could be the problem?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rasschitai, 2020-04-17
@ka40kstas

specify absolute paths, well, read the documentation again, on the topic of error handling

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question