<i id='s5kOH'><tr id='s5kOH'><dt id='s5kOH'><q id='s5kOH'><span id='s5kOH'><b id='s5kOH'><form id='s5kOH'><ins id='s5kOH'></ins><ul id='s5kOH'></ul><sub id='s5kOH'></sub></form><legend id='s5kOH'></legend><bdo id='s5kOH'><pre id='s5kOH'><center id='s5kOH'></center></pre></bdo></b><th id='s5kOH'></th></span></q></dt></tr></i><div id='s5kOH'><tfoot id='s5kOH'></tfoot><dl id='s5kOH'><fieldset id='s5kOH'></fieldset></dl></div>
      • <bdo id='s5kOH'></bdo><ul id='s5kOH'></ul>

    1. <tfoot id='s5kOH'></tfoot>
    2. <small id='s5kOH'></small><noframes id='s5kOH'>

      <legend id='s5kOH'><style id='s5kOH'><dir id='s5kOH'><q id='s5kOH'></q></dir></style></legend>
    3. 如何使用 PHP 和 Mysql DB 下载文件

      How do I download a file using PHP and Mysql DB(如何使用 PHP 和 Mysql DB 下载文件)

          <i id='ErAQ5'><tr id='ErAQ5'><dt id='ErAQ5'><q id='ErAQ5'><span id='ErAQ5'><b id='ErAQ5'><form id='ErAQ5'><ins id='ErAQ5'></ins><ul id='ErAQ5'></ul><sub id='ErAQ5'></sub></form><legend id='ErAQ5'></legend><bdo id='ErAQ5'><pre id='ErAQ5'><center id='ErAQ5'></center></pre></bdo></b><th id='ErAQ5'></th></span></q></dt></tr></i><div id='ErAQ5'><tfoot id='ErAQ5'></tfoot><dl id='ErAQ5'><fieldset id='ErAQ5'></fieldset></dl></div>
            <tbody id='ErAQ5'></tbody>

          1. <tfoot id='ErAQ5'></tfoot>
            <legend id='ErAQ5'><style id='ErAQ5'><dir id='ErAQ5'><q id='ErAQ5'></q></dir></style></legend>
            • <small id='ErAQ5'></small><noframes id='ErAQ5'>

              • <bdo id='ErAQ5'></bdo><ul id='ErAQ5'></ul>
                本文介绍了如何使用 PHP 和 Mysql DB 下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我是新手,我真的很困惑如何下载我设法上传到本地服务器上的文件.

                I am new to this and I am really stuck on how to download a file I have managed to upload on my local server.

                我上传的脚本是 -

                require_once ('dbcon.php');
                
                if(isset($_POST['log'])){
                foreach($_FILES['files']['tmp_name'] as $key => $name_tmp){
                        $file = $_FILES['files']['name'][$key];
                        $tmpnm = $_FILES['files']['tmp_name'][$key];
                        $type = $_FILES['files']['type'][$key];
                        $size = $_FILES['files']['size'][$key];
                        $dir = "file/".$file;
                        $move = move_uploaded_file($tmpnm, $dir);
                if ($move){             
                
                            $query = ("INSERT into dfile VALUES(null,'$file','$type','$size')");
                            $result = $dbLink->query($query);
                
                            if($result){
                                echo "<h4>Upload Complete</h4></br>";
                
                            }else{
                                echo "Error Table DB";
                
                            }
                
                        }
                 }
                
                }
                

                推荐答案

                SomePage.php

                <a href="download.php?FileNo=<?echo $FileNo;?>">File Name</a>
                

                download.php

                $FileNo=$_GET['FileNO'];
                
                //Use Mysql Query to find the 'full path' of file using $FileNo.
                // I Assume $FilePaths as 'Full File Path'.
                
                download_file($FilePaths);
                
                function download_file( $fullPath )
                {
                  if( headers_sent() )
                    die('Headers Sent');
                
                
                  if(ini_get('zlib.output_compression'))
                    ini_set('zlib.output_compression', 'Off');
                
                
                  if( file_exists($fullPath) )
                  {
                
                    $fsize = filesize($fullPath);
                    $path_parts = pathinfo($fullPath);
                    $ext = strtolower($path_parts["extension"]);
                
                    switch ($ext) 
                    {
                      case "pdf": $ctype="application/pdf"; break;
                      case "exe": $ctype="application/octet-stream"; break;
                      case "zip": $ctype="application/zip"; break;
                      case "doc": $ctype="application/msword"; break;
                      case "xls": $ctype="application/vnd.ms-excel"; break;
                      case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
                      case "gif": $ctype="image/gif"; break;
                      case "png": $ctype="image/png"; break;
                      case "jpeg":
                      case "jpg": $ctype="image/jpg"; break;
                      default: $ctype="application/force-download";
                    }
                
                    header("Pragma: public"); 
                    header("Expires: 0");
                    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                    header("Cache-Control: private",false); 
                    header("Content-Type: $ctype");
                    header("Content-Disposition: attachment; filename="".basename($fullPath)."";" );
                    header("Content-Transfer-Encoding: binary");
                    header("Content-Length: ".$fsize);
                    ob_clean();
                    flush();
                    readfile( $fullPath );
                
                  } 
                  else
                    die('File Not Found');
                
                }
                

                这篇关于如何使用 PHP 和 Mysql DB 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                How to parse django style template tags(如何解析 django 样式模板标签)
                What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                php in background exec() function(php 后台 exec() 函数)

                  <i id='r4QN4'><tr id='r4QN4'><dt id='r4QN4'><q id='r4QN4'><span id='r4QN4'><b id='r4QN4'><form id='r4QN4'><ins id='r4QN4'></ins><ul id='r4QN4'></ul><sub id='r4QN4'></sub></form><legend id='r4QN4'></legend><bdo id='r4QN4'><pre id='r4QN4'><center id='r4QN4'></center></pre></bdo></b><th id='r4QN4'></th></span></q></dt></tr></i><div id='r4QN4'><tfoot id='r4QN4'></tfoot><dl id='r4QN4'><fieldset id='r4QN4'></fieldset></dl></div>
                1. <legend id='r4QN4'><style id='r4QN4'><dir id='r4QN4'><q id='r4QN4'></q></dir></style></legend>

                  <small id='r4QN4'></small><noframes id='r4QN4'>

                  <tfoot id='r4QN4'></tfoot>

                    • <bdo id='r4QN4'></bdo><ul id='r4QN4'></ul>
                        <tbody id='r4QN4'></tbody>