宝马娱乐在线城-宝马娱乐在线

来自 互联网络 2019-10-01 21:34 的文章
当前位置: 宝马娱乐在线城 > 互联网络 > 正文

PHP重定向三法

方法一:

复制代码 代码如下:

<?php
$GoTo="index.php";// 假如这里的目标链接取自数据库就实现了动态转向
header(sprintf("Location: %s", $GoTo));
?>

<html>
<head>
    <meta charset="utf-8">
    <title>index_uploads</title>
</head>
<body>
    <form action="uploads.php" method="post" enctype="multipart/form-data">
        <input type="file" name="file[]">
        <br>
        <input type="file" name="file[]">
        <br>
        <input type="file" name="file[]">
        <br>
        <input type="file" name="file[]">
        <br>
        <input type="file" name="file[]">
        <br>
        <input type="submit" value="uploads">
    </form>
</body>
</html>

方法二:

index_uploads.php

<?php echo "<script>window.location ="$PHP_SELF";</script>";?>

复制代码 代码如下:

方法三:

<?php
    echo "<pre>";
    print_r($_FILES);
    echo "</pre>";

<?php echo "<META HTTP-EQUIV="Refresh" CONTENT="0;URL=index.php">";?>

    $count = count($_FILES['file']['name']);

    for ($i = 0; $i < $count; $i++) {
        $tmpfile = $_FILES['file']['tmp_name'][$i];
        $filefix = array_pop(explode(".", $_FILES['file']['name'][$i]));
        $dstfile = "uploads/files/".time()."_".mt_rand().".".$filefix;

        if (move_uploaded_file($tmpfile, $dstfile)) {
            echo "<script>alert('succeed!');window.location.href='listdir.php';</script>";
        } else {
            echo "<script>alert('fail!');window.location.href='index_uploads.php';</script>";
        }
    }

uploads.php

复制代码 代码如下:

<?php
    header("content-type:text/html;charset=utf-8");
    $dirname = "uploads/files";

本文由宝马娱乐在线城发布于互联网络,转载请注明出处:PHP重定向三法

关键词: