K
K
khodos_dmitry2020-05-30 17:04:11
PHP
khodos_dmitry, 2020-05-30 17:04:11

Why doesn't move_upload_files move files?

if (isset($_FILES['image']) && $_FILES['image']['error'] === 0) {
            $type_arr = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp'];
            if (in_array($_FILES['image']['type'], $type_arr)) {
                $fileNameCmps = explode(".", $_FILES['image']['name']);
                $ext = strtolower(end($fileNameCmps));
                echo $dir = str_replace('\\', '/', __DIR__ . '/../../../../image/users/' . $this->id . '.' . $ext);
                if (move_uploaded_file($_FILES['tmp_name'], $dir)) {
                    $this->image = $this->id . '.' . $ext;
                } else {
                    throw new \Exception('При перемещении изображения произошла ошибка!');
                }
            } else {
                throw new InvalidFormatException('Картинки должны быть формата: jpg, jpeg, png, gif, bmp');
            }
        } else {
            throw new \Exception('При загрузке изображения произошла ошибка!');
        }

An error occurs: An error occurred while moving the image!
Why?
The paths are correct.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-05-30
@khodos_dmitry

Well at least

if (move_uploaded_file($_FILES['image']['tmp_name'], $dir))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question