回去时如何记住加载的文件?

时间:2016-10-19 10:17:26

标签: php file back

我正在开发一个Web应用程序,我在php中使用上传方法上传一个文件,在下一页(upload.php)中,我处理数据并显示内容,但我有一个后退按钮。

的index.php

<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>

upload.php的

<form action="process.php" method="post" enctype="multipart/form-data">
        Select image to upload:
        <input type="file" name="fileToUpload" id="fileToUpload">
        <input type="submit" value="Upload Image" name="submit">
</form>
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
      Select image to upload:
      <input type="file" name="fileToUpload" id="fileToUpload">
      <input type="submit" value="Upload Image" name="submit">
 </form>

procees.php

<button onclick="goBack()">Go Back</button>
<script>
function goBack() {
    window.history.back();
}
</script> 

<?php
   /*process uploaded file*/
?>

当我单击“返回”按钮时,我又需要上传文件,如果有任何方法可以记住同一个文件(我上传的文件),即使我回去了吗?

1 个答案:

答案 0 :(得分:0)

不要使用window.history.back(); 只需将用户重定向到您希望他去的页面,并在显示按钮之前处理图像,这是一个很好的做法