网络编程 - 从webserver向客户端发送文件

时间:2017-09-28 18:08:25

标签: php network-programming

我写了一个php脚本来将文件上传到网络服务器。在那里我也可以下载它。我想将文件从服务器转移到客户端,因此每次上传文件时,它都会被推送到客户端。甚至可以用php脚本来处理它,除了PHP脚本之外我在哪里定义这些操作,还是可以集成?

我的索引和上传文件的php脚本:

指数:     

$sql  = "SELECT * FROM documents";
$res = mysqli_query($con, $sql);

?>

<html>
    <head>
        <title>Documents</title>
    </head>
<body>
    <nav id="nav">
        <ul>
            <li><a href="upload.php">Upload</a></li>
            <li><a href="downloadlist.php">Download</a></li>
        </ul>
    </nav>         
</body>
</html>

上传:

 <?php
    include("db.php");

    if(isset($_POST['submit'])){

        $name = $_FILES['myfile']['name'];
        $tmp_name = $_FILES['myfile']['tmp_name'];

        if($name){

            $location = "/storage/ssd2/932/2536932/uploads/$name";
            move_uploaded_file($tmp_name, $location);
            $query = mysqli_query($con, "INSERT INTO documents (name, path) VALUES('$name', '$location')");
            header('Location: index.php');
        }
        else 
            die("Please select a file.");       
    }   
    ?>

    <html>
    <head>
        <title>Upload File</title>
    </head>
    <body>
        <form action="upload.php" method="post" enctype="multipart/form-data">
            <label>Browse File:</label>

            <input type="file" name="myfile">
            <input type="submit" name="submit" value="Upload" onclick="index.php">
        </form>    
    </body>    
    </html>

0 个答案:

没有答案