Answer the question
In order to leave comments, you need to log in
Why can't php upload images to the server?
Hello everyone, there was a problem when uploading images to the server through the site form.
Here is the form code:
<form role="form" action="generate.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="img1" class="sr-only">Выберите изображение "ДО"</label>
<div class="file_upload btn btn-default">Выбрать фото "ДО"<input type="file" name="img1"></div>
</div>
<div class="form-group">
<label for="img2" class="sr-only">Выберите изображение "ПОСЛЕ"</label>
<div class="file_upload btn btn-default">Выбрать фото "ПОСЛЕ"<input type="file" name="img2"></div>
</div>
<button type="submit" name="generate" class="btn btn-primary btn-lg btn-max" style="width: 100%;">Получить результат</button>
</form>
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$data = $_POST;
if (isset($data['generate'])) {
if($_FILES['img1']['error'] == 0) { // Нет ошибок
$name = $_FILES['img1']['name'];
$name1 = 'do.jpg';
move_uploaded_file($_FILES['img1']['tmp_name'],$name1);
}
if($_FILES['img2']['error'] == 0) { // Нет ошибок
$name = $_FILES['img2']['name'];
$name2 = 'posle.jpg';
move_uploaded_file($_FILES['img2']['tmp_name'],$name2);
}
}
?>
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