dts777777 2014-05-28 10:31
浏览 22
已采纳

PHP - 下载给定视频网址的对话框

I am pretty new in php .so hopefully this all make sense . I am using below script to extract url from database.I want down-loader will popup in browser while reading the url from database....

 $q="  Select url from videos where id = '".$_REQUEST['id']."'   ";
     $result=mysql_query($q);
           while( $rows =mysql_fetch_assoc($result) )
            {
        $url=$rows['url '];
    //here i want code to send this url to down-loader of browser..
    //and browser should popup the down-loader
        $myarray1=array("url "=>$url );
             }

I have searched codes on google but i don't understand how to use for this scenario...

  • 写回答

1条回答 默认 最新

  • douou9786 2014-05-28 10:52
    关注

    First of all, you need to fix the SQL Injection problem. Use MySQLi instead of MySQL

    Here's a code:

    $request_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
    if(!empty($request_id)){
        $mysqli = new mysqli("localhost", "user", "password", "database_name");
        $request_id = $mysqli->real_escape_string($request_id);
        $query = "SELECT url FROM videos WHERE id='" . $request_id . "'";
        $query_result = $mysqli->query($query);
        if(!empty($query_result)){
            if($query_result->num_rows > 0){
                $my_result_array = array();
                while($row = $query_result->fetch_assoc()){
                    $my_result_array[] = $row['url'];
                }
            }
        }
        mysqli_close($mysqli);
    }
    

    Concerning the download problem, you need to redirect the user to a PHP page with a specific header

    <?php
    $file_name = "";
    header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    header("Content-Disposition: attachment;filename=\"" . $file_name . "\"");
    header("Cache-Control: max-age=0");
    ?>
    

    You need to add the $file_name and the specific Content-Type. Here's a list of Content-Types: http://davidwalsh.name/php-header-mime

    In order to redirect a user to the download page, you can use the PHP header() function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效