如何让我的php脚本显示上传文件的下载链接?

时间:2015-05-18 21:00:26

标签: php nginx upload web

我的php脚本需要一些帮助才能将文件上传到我的服务器:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>File Upload</title>

        <link rel="icon" type="image/png" href="icons/favicon.png">
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <script src="js/bootstrap.min.js"></script>
        <script src="js/jquery-1.11.3.min.js"></script>
        <script src="js/bootstrap-filestyle.js"></script>

        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    </head>

    <body>
        <div class="container" style="margin-top: 30px;margin-bottom: 30px">
            <div class="row">
                <div class="span12">
                    <h2 style="text-align: center;"><strong>File Upload</strong></h2>
                    <div class="well">
                        <form role="form" enctype="multipart/form-data" method="post">
                            <h3>Choose your file</h3>
                            <hr>
                            <div class="row">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <input type="file" name="example" id="input01" class="filestyle" data-buttonBefore="true">
<?php 

$dir_upload = '/usr/local/nginx/html/test/upload/'; 
$max_size = 200000000;

$file = $_FILES['example'];

if ($file['size'] <= $max_size && $file['size'] > 0) {
    $new_name = time() . '-' . $file['name'];
    $copied = copy($file['tmp_name'], $dir_upload . $new_name);

    if ($copied) {
        print("Successfully uploaded to server");
    } else {
        print("An unknown error has occurred.");
    }
} else {
    print("");
}
?>
                                    </div>

                                </div>
                                <div class="col-xs-2">
                                    <div class="form-group">
                                        <button type="submit" class="btn btn-primary">
                                            <span class="glyphicon glyphicon-ok"></span> Upload File
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <footer>
                    <center>
                    &copy; <?php echo date("Y"); ?> Copyright Alydus.net
                    </center>
                    </footer>

我是PHP的新手,您能告诉我如何显示上传文件的下载链接吗?

1 个答案:

答案 0 :(得分:0)

您可以执行类似

的操作
<a href="<?php echo $dir_upload.$new_name?>">Download</a>