Afisare mesaj si refresh la upload in php

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
sterica
Mesaje:285

Afisare mesaj si refresh la upload in php

Salutare,
Am urmatorul cod care imi face upload de fisiere in server, insa nu stiu cum sa fac ca atunci cand fisierul este urcat pe server sa imi arata un mesaj: "Fisier uploadat cu succes"
Codul din index.php

Cod: Selectaţi tot

  <form action="upload_file.php" method="post" enctype="multipart/form-data" name="upload_file" autocomplete="off"><br>
    <label for="UploadFileField"></label><br>
    <input type="file" name="UploadFileField"/>
    <input type="submit" name="UploadButton" value="Upload" />
  </form>
si codul pentru upload_file.php

Cod: Selectaţi tot

<?php
if (isset ($_FILES['UploadFileField'])){
  $UploadName = $_FILES['UploadFileField'] ['name'];
  $UploadName = mt_rand (100000, 999999).$UploadName; 
  $UploadTmp = $_FILES['UploadFileField'] ['tmp_name'];
  $UploadType = $_FILES['UploadFileField'] ['type'];
  $FileSize = $_FILES['UploadFileField'] ['size'];

  $UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);

  if(($FileSize > 1250000)){
    die ("Error - File to big");
  }

  if(!$UploadTmp) {
    die ("No File Selected");
  }
  else {
    if (move_uploaded_file($UploadTmp, "Upload/$UploadName")) {
        echo "Successfully inserted";
        header('Location: /index.php');
    }
    else {
      echo  "Something went wrong";
      header('Location: /index.php');
    }
  }
}
 ?>
Linia de cod: echo "Successfully inserted"; nu functioneaza dupa ce se face upload-ul.
Multumesc!

MarPlo Mesaje:4343
Salut
Dupa cum e codul, nu are cum sa apara textul de la "echo" findca linia de cod:

Cod: Selectaţi tot

header('Location: /index.php');
face redirect la pagina index la nivel de server, inainte sa fie ceva trimis la browser; presupun ca pentru a evita retrimierea datelor la refresh.

- Ai putea face o combinatie cu javascript (fara header() ), sa afiseze mesajul intr-un alert(), dupa care sa faca redirect.
Asa:

Cod: Selectaţi tot

if(move_uploaded_file($UploadTmp, "Upload/$UploadName")){
  echo '<script> alert("Successfully inserted"); window.location ="/index.php";</script>';
}

sterica Mesaje:285
functioneaza perfect. Multumesc mult!

Subiecte similare