Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

508
Vistas
How to redirect to success page after uploading file using php?

I am trying to redirect to another page after a successful upload.

So I searched for similar answers on stackoverflow but non seems to solve my problem.

This is my form:

    <form enctype="multipart/form-data"
        action="<?php print $_SERVER['PHP_SELF']?>"  method="post">
    <p><input type="hidden" name="MAX_FILE_SIZE" value="9000000" /> <input
        type="file" name="pdfFile" /><br />
    <br />
    <input type="submit" value="upload"  /></p>
    </form>

This is my php which includes the header that redirects

<?php
if ( isset( $_FILES['pdfFile'] ) ) {
    if ($_FILES['pdfFile']['type'] == "application/pdf") {
        $source_file = $_FILES['pdfFile']['tmp_name'];
        $dest_file = "upload/".$_FILES['pdfFile']['name'];

        if (file_exists($dest_file)) {
            print "The file name already exists!!";
        }
        else {
            move_uploaded_file( $source_file, $dest_file )
            or die ("Error!!");
            if($_FILES['pdfFile']['error'] == 0) {
                print "Pdf file uploaded successfully!";
                print "<b><u>Details : </u></b><br/>";
                print "File Name : ".$_FILES['pdfFile']['name']."<br.>"."<br/>";
                print "File Size : ".$_FILES['pdfFile']['size']." bytes"."<br/>";
                print "File location : upload/".$_FILES['pdfFile']['name']."<br/>";
                header('Location: success.php');
            }
        }
    }
    else {
        if ( $_FILES['pdfFile']['type'] != "application/pdf") {
            print "Error occured while uploading file : ".$_FILES['pdfFile']['name']."<br/>";
            print "Invalid  file extension, should be pdf !!"."<br/>";
            print "Error Code : ".$_FILES['pdfFile']['error']."<br/>";
        }
    }
}
?>
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

(From php.net) php header

If you want to use outputs first use Javascript or Html code

<meta http-equiv="refresh" content="2; URL=http://stackoverflow.com">

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda