|
 |
|
PHP Upload รบกวนช่วยเขียน Ajax รับส่ง Form ให้หน่อยครับ !!!!!!!!!! |
|
 |
|
|
 |
 |
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input name="type" type="hidden" value="uploadfile" />
Name :
<input type="text" name="txtName">
<br />
VDO Clip :
<input type="file" name="filUpload">
<br />
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
Code (PHP)
<?
if ($_POST['type']=="uploadfile"){
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"video/".$_FILES["filUpload"]["name"]))
{
echo "Copy/Upload Complete</br><br>";
function Random($length){
$possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$str = "";
while(strlen($str)<$length){
$str.=substr($possible,(rand()%strlen($possible)),1);
}
return $str;
}
$random = Random(15);
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("video");
$strSQL = "INSERT INTO files ";
$strSQL .="(v,Name,FilesName,Size,ContentType)
VALUES ('$random','".$_POST["txtName"]."' ,'".$_FILES["filUpload"]["name"]."' ,'".$_FILES["filUpload"]["size"]."' ,'".$_FILES["filUpload"]["type"]."')";
$objQuery = mysql_query($strSQL);
mysql_close($objConnect);
}
}
?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-12-30 19:19:07 |
By :
nukedonut1 |
View :
1031 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เท่าที่เคยทำมาจะใช้อยู่ 2 อย่างคือ jQuery และ jQuery Form Plugin
Form Upload
<html>
<head>
<title>Ajax form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
$(document).ready(function(e) {
$('#Upload').click(function(e) {
$('#formupload').ajaxForm(function(data){
$('#result').html(data);
}).submit();
});
});
</script>
</head>
<body>
<form id="formupload" action="action.php" method="post" enctype="multipart/form-data" name="formupload">
<input type="file" name="YouFile[]" id="YouFile[]"><br>
<button id="Upload">อัพโหลด</button><br>
<div id="result"></div>
</form>
</body>
</html>
action.php
<?
$Ojb = $_FILES['YouFile'];
$detail = array(
'name' => $Ojb['name'],
'type' => $Ojb['type'],
'tmp_name' => $Ojb['tmp_name'],
'error' => $Ojb['error'],
'size' => $Ojb['size']
);
echo '<pre>';
print_r($detail);
echo '</pre>';
?>
|
 |
 |
 |
 |
Date :
2012-12-31 02:00:59 |
By :
Krungsri |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|