文件上传完成后重定向到新页面

时间:2011-09-10 10:07:35

标签: php

我的文件上传有以下php文件,如果文件上传完成后如何重定向到新页面,请提前感谢。

<?php
echo <<<_END
<html>

<title>PHP Form Upload</title></head><body>
<form method = 'post' action='testupload.php' enctype='multipart/form-data'>
Select File: <input type='file' name='filename' size='10' />
<input type='submit' value='Upload' />
</form>


_END;


 if($_FILES)
{
$a = uniqid();
   $saveto =  $a.".jpg";;
 // $name = $_FILES['filename']['name'];
  move_uploaded_file($_FILES['filename']['tmp_name'],  $saveto);
  $typeok = TRUE;

  switch($_FILES['filename']['type'])
   {
     case "image/gif": $src = imagecreatefromgif($saveto); break;

       case "image/jpeg":
         case "image/pjpeg":  $src = imagecreatefromjpeg($saveto); break;

      case "image/png": $src = imagecreatefrompng($saveto); break;

       default: $typeok = FALSE; break;
    }


     echo "Upload image '$saveto'<br/><img src='$saveto' />";
  }
  if ($_FILES["filename"]["size"] > 2000)
     {
      echo "Error: file is too big" . $_FILES["file"]["error"] . "<br />";
     }

  echo"</body></html>";

   ?>    

2 个答案:

答案 0 :(得分:2)

action中正常执行重定向,即testupload.php

答案 1 :(得分:2)

在所有内容之前为_FILES设置if语句,并在上传完成时(可能是move_uploaded_file),输入此代码

header("Location: newlocation.php");