Jump to content

[SOLVED] file upload with redirect


dandan321

Recommended Posts

Hello,

 

If anyone can help with this it would be greatly appreciated.

 

I am trying to upload files to my server and then have the page redirect to another page, like a thankyou page or another page to where I can pass some variables. However when I run this script and I add  ---- Header("Location: somepage.php"); ----- I get the following error

 

 

PHP Warning: Cannot modify header information - headers already sent by (output started at C:\hshome\martinar\martinarts.org\test\test.php:3) in C:\hshome\martinar\martinarts.org\test\test.php on line 26

 

 

 

below is my code for both the html and the php

 

 

 

 

 

form.htm

 

<html>

<head></head>

<body>

<form action="test.php" method="post" enctype="multipart/form-data">

<br><br>

Choose a file to upload:<br>

<input type="file" name="file"><br>

<input type="submit" name="submit" value="submit">

<input type="hidden" name="something" value="yeah buddy!">

</form>

</body>

</html>

 

=========================================

 

test.php

 

 

<?php

if ($HTTP_POST_VARS['submit']) {

  print_r($HTTP_POST_FILES);

  if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) {

    $error = "You did not upload a file!";

    unlink($HTTP_POST_FILES['file']['tmp_name']);

    // assign error message, remove uploaded file, redisplay form.

  } else {

    //a file was uploaded

    $maxfilesize=10240000000;

 

    if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) {

      $error = "file is too large";

      unlink($HTTP_POST_FILES['file']['tmp_name']);

      // assign error message, remove uploaded file, redisplay form.

    } else {

      if ($HTTP_POST_FILES['file']['type'] != "image/gif" AND $HTTP_POST_FILES['file']['type'] != "image/pjpeg") {

        $error = "This file type is not allowed";

        unlink($HTTP_POST_FILES['file']['tmp_name']);

        // assign error message, remove uploaded file, redisplay form.

      } else {

      //File has passed all validation, copy it to the final destination and remove the temporary file:

copy($HTTP_POST_FILES['file']['tmp_name'],"/hshome/martinar/martinarts.org/test/files/".$HTTP_POST_FILES['file']['name']);

      unlink($HTTP_POST_FILES['file']['tmp_name']);

      print "File has been successfully uploaded!";

      Header("Location: somepage.php");

      exit;

    }

    }

  }

}

?>

 

 

 

thanks, Dan

Link to comment
https://forums.phpfreaks.com/topic/61958-solved-file-upload-with-redirect/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.