php基礎教程:檔案以二進位形式上傳並放入資料庫

來源:互聯網
上載者:User

 

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=檔案上傳\">";}}}?>


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.