• 技术文章 >php教程 >php手册

    php基础教程:文件以二进制形式上传并放入数据库

    PHP中文网PHP中文网2017-03-21 14:18:41原创1064
    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"> </td>
        <td width="200"> </td>
        <td width="55"> </td>
      </tr>
      <form name="form1" method="post" action="index_ok.php" enctype="multipart/form-data">
      <tr>
        <td height="40"> </td>
        <td align="center" valign="middle">
         <input name="file2" type="file" id="file2" size="15" maxlength="150"></td>
        <td> </td>
      </tr>
      <tr>
        <td height="30"> </td>
        <td align="center"><input type="submit" name="Submit" value="提交"></td>
        <td> </td>
      </tr>
      </form>
      <tr>
        <td height="30"> </td>
        <td> </td>
        <td> </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=文件上传\">";}
    }}
    ?>

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:array multisort:数组 php array_multisort处理 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • php根据用户语言跳转相应网页• PHP弹出提示框并跳转到新页面即重定向到新页面• PHP 动态生成静态HTML页面示例代码• 对MVC的理解,MVC理解• ThinkPHP框架里隐藏index.php,thinkphpindex.php
    1/1

    PHP中文网