程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> PHP基礎:文件上傳

PHP基礎:文件上傳

編輯: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: 0px;
	margin-top: 00px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style></head>
<script language="Javascript">
function file1(form1){
 if(form1.file.value==""){
alert("上傳文件不能為空!!");
form1.file.focus();
return;}
form1.submit();}
</script>
<body>
<table width="462" height="162" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="140" height="68">&nbsp;</td>
    <td width="246">&nbsp;</td>
    <td width="69">&nbsp;</td>
  </tr>
  <form name="form1" method="post" action="index_ok.PHP">
  <tr>
    <td height="28">&nbsp;</td>
    <td align="left" valign="middle"><input name="file" type="file" size="22"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="30">&nbsp;</td>
    <td align="center" valign="top"><input type="submit" name="Submit" value="提交" 
     onClick="file1(form1);"></td>
    <td>&nbsp;</td>
  </tr>
  </form>
  <tr>
    <td height="36">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</Html>

function.PHP:

<?php 
session_start();
include("conn.php");
       $data=date("Y-m-d");
       $file1="file_name1";
if($Submit==true){
    $query=MySQL_query("insert into tb_file1 (file_name,file_text,data)values('$file1','$file','$data')");
if($query==true){
echo "文件上傳成功!!";
echo "<meta http-equiv=\"refresh\" content=\"3 url=index.php\">";
}else{
echo "上傳失敗!!";
echo "<meta http-equiv=\"refresh\" content=\"3 url=index.PHP\">";}}
?>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved