L
L
lkotov992020-04-13 17:05:01
PHP
lkotov99, 2020-04-13 17:05:01

How to follow the link after uploading images?

How to follow the link after the file is successfully uploaded?
Here is the code, I insert
header('Location: https://site.ru/success.php');
the transition for some reason is not executed.

Here is the code in full

<?php
    // если была произведена отправка формы
    if(isset($_FILES['file'])) {
      // проверяем, можно ли загружать изображение
      $check = can_upload($_FILES['file']);
    
      if($check === true){
        // загружаем изображение на сервер
        make_upload($_FILES['file']);
        echo "<strong>Фотографии успешно загружены!</strong>";
    header('Location: http://site.ru/success.php');
      }
      else{
        // выводим сообщение об ошибке
        echo "<strong>$check</strong>";  
      }
    }
    ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Artemyev, 2020-04-13
@Vitaly48

You first send a text about the successful upload of photos, and then set the redirect header, but you can’t do that. Headers must be set before the first byte is sent.
take away

echo "<strong>Фотографии успешно загружены!</strong>";

And in general, if you do a redirect in this way, then there is no point in outputting something using echo, because the browser will not display the page, but will immediately follow the link in the "Location" header

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question