|  |  | 
          
            | [From upload/head] 
 <?
	session_start();
	if($_SESSION['UserID'] == "")
	{
		echo "Please Login!";
		exit();
	}
	mysql_connect("localhost","root","6845");
	mysql_select_db("dc");
	mysql_query("SET NAMES UTF8");
	$strSQL = "SELECT * FROM member WHERE UserID = '".$_SESSION['UserID']."' ";
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style_uploadfile.css" type="text/css" />
<title>Untitled Document</title>
</head>
<form action="Save_Upload.php" method="post" name="formupload" enctype="multipart/form-data">
<table width="100%" align="center" cellpadding="0" cellspacing="3" class="table">
  <tr>
    <td colspan="4" class="tb1" style="white-space:normal"><strong><img src="images/formupload.png" align="absmiddle"/> Form Uploadfile</strong></td> 
  </tr>
 
<tr>
     <td  class="tbl1" style="white-space: nowrap;"><div align="right"><strong>วันที่อัพไฟล์</strong></div></td>
     <td colspan="1"  valign="top" class="tbl1" style="white-space: nowrap;"><input name="dservice" type="text" class="idle" id="dservice" autocomplete="off"  readonly="true"value="<? $date = date("d-m-y");$time = date("H-i-s");print $date;?>"/>
     </td>
     </tr>
     <tr>
     <td  valign="top" class="tbl1" style="white-space: nowrap;"><div align="right"><strong>ชื่อผู้อัพไฟล์</strong></div></td>
                <td colspan="3"  valign="top" class="tbl1" style="white-space: nowrap;"><input name="Name_M" type="text" class="idle" id="Name_M" autocomplete="off"  readonly="true" value="<?=$objResult["Name_M"];?>"/>
                <div style="display:none;"> <input  name="UserID" type="text" class="idle" id="UserID" autocomplete="off"  readonly="true" value="<?=$objResult["UserID"];?>"/> </div>
     </td>
     </tr>
     <tr>
     <td valign="top" class="tbl1" style="white-space:nowrap;"><div align="right"><strong>ชื่อไฟล์</strong></div></td>
     <td colspan="3" valign="top" class="tbl1" style="white-space:nowrap;"><input name="txtName" type="text" class="idle" id="Name_U"   value=""/></td>
     </tr>
     <tr>
     <td valign="top" class="tbl1" style="white-space:nowrap;"><div align="right"><strong>รายละเอียด</strong></div></td>
     <td colspan="3" valign="top" class="tbl1" style="white-space:nowrap;"><textarea name="details" class="idle" id="Details" cols="45" rows="5"></textarea></td>
     </tr>
     <tr>
     <td valign="top" class="tbl1" style="white-space:nowrap;"><div align="right"><strong>ไฟล์ที่จะอัพ</strong></div></td>
     <td colspan="3" valign="tbl1" class="tbl1" style="white-space:nowrap;"><input name="fileUpload" type="file" class="idle" id="FilesName" value="" /></td>
     </tr>
     <tr>
     <td  valign="top" class="tbl1" style="white-space: nowrap;"> </td>
     <td colspan="3"  valign="top" class="tbl1" style="white-space: nowrap;"><button type="submit" name="button" id="button" ><img src="images/save.png" alt="" width="16" height="16" align="absmiddle" /> บันทึก </button></td></tr>
                </table>
                </form>
               
 [head]Save Upload
 
 <? 
session_start();
if($_SESSION['UserID'] == "")
	{
		echo "Please Login!";
		exit();
	}
ob_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style_uploadfile.css" type="text/css" />
<title>123</title>
</head>
<br>
<body>
<style type="text/css">
    * {	
	    margin:0;
		padding:0;
		font:"Times New Roman", Times, serif;
	}
    #wrapper{
	    width:420px;
	    margin: 200 auto;
		padding:20px 20px 20px 20px; 
		border:20px solid #FF8000;
	}
   .box1 {
	    width:430px;
	    background:  url(images/tile2.gif) repeat-y; 	
		position:relative;
	}
  .box1:before {
       content:  url(images/top2.gif);
	   display:block;
  }
  .box1:after {
       content:  url(images/bottom2.gif);
	   display:block;
  }
  .txt{
     padding: 0 10px;
  }
 
</style>
<div id="wrapper">
   		 <div class = "box1">
	   	<p class="txt">
<?
	
if ((($_FILES["fileUpload"]["type"] == "image/gif")
|| ($_FILES["fileUpload"]["type"] == "image/jpeg")
|| ($_FILES["fileUpload"]["type"] == "image/pjpeg"))
&& ($_FILES["fileUpload"]["size"] < 1000000))
 {
 if ($_FILES["fileUpload"]["error"] > 0)
 {
 echo "Error: " . $_FILES["fileUpload"]["error"] . "<br />";
 }
 else
 {
 echo "Upload: " . $_FILES["fileUpload"]["name"] . "<br />";
 echo "Type: " . $_FILES["fileUpload"]["type"] . "<br />";
 echo "Size: " . ($_FILES["fileUpload"]["size"] / 1024) . " Kb<br />";
 echo "Stored in: " . $_FILES["fileUpload"]["tmp_name"];
 
			 }
			 if(move_uploaded_file($_FILES["fileUpload"]["tmp_name"],"myfile/".$_FILES["fileUpload"]["name"]))
				
				 
				 //*** Insert Record ***//
				$objConnect = mysql_connect("localhost","root","6845") or die("Error Connect to Database");
				$objDB = mysql_select_db("dc");
				mysql_query("SET NAMES UTF8");
				$Date =date("d/m/y");
				$Time =date("H:i:s");
				$strSQL = "INSERT INTO files ";
				$strSQL .="(UserID,Name,Date,Time,FilesName,Details,Name_M) VALUES ('".$_POST["UserID"]."','".$_POST["txtName"]."','$Date','$Time','".$_FILES["fileUpload"]["name"]."','".$_POST["details"]."','".$_POST["Name_M"]."')";
				$objQuery = mysql_query($strSQL);
				
			 } else {//ถ้าไฟล์ที่อัพไม่เป็นไฟล์รูป หรือขนาดไฟล์เกิน 1000000
		echo "ไฟล์ผิดประเภทหรือมีขนาดใหญ่เกินไป";
	}
?>
<a href="ViewFiles.php">    View files</a>
</p>
</div>
</div>
 
 คือผมจะเพิ่มเติมตรงส่วน ให้ตรวจสอบชื่อไฟล์ที่อัพ เพื่อป้องกันชื่อไฟล์เหมือนกัน มันจะได้ไม่บันทึกทับลงไปอะครับ ผมจะเขียนเพิ่มเติมยังไงดีครับ
 
 ช่วยแนะนำหน่อยครับ จะเป็น การเช็คชื่อไฟล์ หรือ เราสามารถเปลี่ยนชื่อไฟล์เองได้ไหมครับ
 
 เช่น ไฟล์เดิม  Goodjob.png เปลี่ยนให้เป็น Goodjob(ตามด้วยเวลา หรือวันที่).png แบบนี้ได้ไหมครับ
 
 
 
 Tag : PHP, MySQL, HTML/CSS
 
 
 |  
            | 
 ประวัติการแก้ไข
 2012-08-10 14:15:33
 |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2012-08-10 10:09:32 | By :
                          cappuczino | View :
                          1038 | Reply :
                          3 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |