A
A
Andrey Kotosin2018-02-04 14:49:07
PHP
Andrey Kotosin, 2018-02-04 14:49:07

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>

Here is the generate.php handler
<?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);
        }
}
?>

Doesn't show any errors. Downloads files, but not all, for example, photos taken on the iPhone 5s or iPhone SE are not loaded. Here are links to 2 files that DEFINITELY DO NOT LOAD.
https://yadi.sk/i/6WQVnNao3S5Rbq
https://yadi.sk/i/k-JxYHgt3S5Rc6
Tell me where to drip, I've already rummaged through everything, it should work (it loads other images) but it doesn't work ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2018-02-04
@402d

if($_FILES['img1']['error'] == 0) { // Нет ошибок
            $name = $_FILES['img1']['name'];
            $name1 = 'do.jpg';
            move_uploaded_file($_FILES['img1']['tmp_name'],$name1);
        }else{ 
           echo "код ошибки ". $_FILES['img1']['error'];
       }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question