zoukankan      html  css  js  c++  java
  • PHP将二进制文件存入数据库以及从数据库中读取二进制文件

    <?php
    $file = 'abcd.sqlite';
    
    mysql_connect('localhost','root','123456');
    mysql_select_db('zblog');
    mysql_query('set names utf8');
    
    /*
    $backup_stream = file_get_contents($file);
    // var_dump($backup_stream);exit;
    // $PSize = filesize($file); 
    // $backup_stream = addslashes(fread(fopen($file, "r"), $PSize)); 
    // var_dump($backup_stream);exit;
    
    $sql = 'insert into t_user(backup) values("'. addslashes($backup_stream) .'")';
    mysql_query($sql) ;
    echo mysql_error();
    
    
    exit;
    */
    
    
    $sql = 'select id,backup from t_user limit 1';
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=db_backup.sqlite');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . strlen($row['backup']));
    // ob_clean();
    // flush();
    // readfile($file);
    echo $row['backup'];
    exit;
    
    
    
    /*
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
    */
    

      

  • 相关阅读:
    求树中两个节点的最低公共祖先
    [2014校招笔试]判断单链表是否有环?
    二叉树的遍历
    求所有划分集合
    用rand5()生成rand(n)
    由等概率生成的0和1构建rand()函数
    等概率生成0和1
    求输出和为n的所有连续自然数序列
    求正整数n的所有因子
    css 2D转换总结
  • 原文地址:https://www.cnblogs.com/adtuu/p/4723451.html
Copyright © 2011-2022 走看看