Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    <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/>";
        }
    }
}
?>

>Solution :

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">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading