zoukankan      html  css  js  c++  java
  • php文件以二进制形式上传并放入到数据库中

    conn.php:

    <?php 
    $id=mysql_connect('localhost','root','root');
    mysql_select_db("db_database12",$id);
    mysql_query("set names gb2312");
    ?>

    index.php:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>上传文件到服务器</title>
    <style type="text/css">
    <!--
    body {
    	margin-left: 00px;
    	margin-top: 0px;
    	margin-right: 0px;
    	margin-bottom: 0px;
    }
    -->
    </style></head>
    
    <body>
    <table width="385" height="185" border="0" cellpadding="0" cellspacing="0" >
      <tr>
        <td width="130" height="85">&nbsp;</td>
        <td width="200">&nbsp;</td>
        <td width="55">&nbsp;</td>
      </tr>
      <form name="form1" method="post" action="index_ok.php" enctype="multipart/form-data">
      <tr>
        <td height="40">&nbsp;</td>2881064151
        <td align="center" valign="middle">
         <input name="file2" type="file" id="file2" size="15" maxlength="150"></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="30">&nbsp;</td>
        <td align="center"><input type="submit" name="Submit" value="提交"></td>
        <td>&nbsp;</td>
      </tr>
      </form>
      <tr>
        <td height="30">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
    
    

    index_ok.php:

    <?php 
    session_start(); 
    include("conn.php");?>
    <?php
     if($Submit=="提交"){
    $data=date("Y-m-d");
    $file_name="file2";
    $path = './upfiles/'. $_FILES['file2']['name'];
    if (move_uploaded_file($_FILES['file2']['tmp_name'],$path)) { 
    	$query="insert into tb_file2(file_name,file_text,data)values('$file_name','$path','$data')";
    	$result=mysql_query($query);
    	if($result=true){ 
    	echo "上传成功!!";
    	echo "<meta http-equiv="Refresh" content="3;url=index.php?lmbs=文件上传">"; 
    	}else{echo "文件上传失败!!";
              echo "<meta http-equiv="Refresh" content="3;url=index.php?lmbs=文件上传">";}
    }}
    ?>
  • 相关阅读:
    诗人就是“情场浪子”的代名词?
    微博营销,开启营销的新时代
    网店成功之道:卖家应有4种心态(实战交流)
    一枚钉子前进
    推动中国文学的发展,我义不容辞
    微博营销,再次引爆网络江湖
    微博营销,不仅仅是粉丝
    邮件群发软件版本升级公告
    如何让自己在浩瀚的网海中脱颖而出
    如何定时关机【windows/linux】
  • 原文地址:https://www.cnblogs.com/cbryge/p/6033497.html
Copyright © 2011-2022 走看看