• 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;
    }
    */
    

      

  • 相关阅读:
    boost 1.49在vs 2005下编译的方法
    Mathematics for Computer Graphics
    字符串和字符数组长度
    四个月的学习心得
    话说stm32f10x-FSMC的配置与频率
    一些笔试题,大家都来围观呀~
    简单的生产者消费者-(windows下)
    STM32f10x下软件模拟IIc读写si5326问题
    usb枚举阶段(转载)
    STM32 GPIOB_PIN3复用功能小分析
  • 原文地址:https://www.cnblogs.com/adtuu/p/4723451.html
Copyright © 2020-2023  润新知