|
|
|
รบกวนช่วยดูโค๊ดให้หน่อยนะค่ะ คือไม่สามารถอัพไฟล์ลง DB ได้คะ |
|
|
|
|
|
|
|
upload.php
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script href="bootstrap/js/bootstrap.min.js" rel="stylesheet"></script>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/js/bootstrap.min.js"></script>
</head>
<script>
$(document).ready(function() {
$("form").validate({
rules: {
Name: {required: true},
Description: {required: true},
Language: {required: true},
Advisor: {required: true},
rdoname: {required: true},
CourProj: {required: true},
Year: {required: true},
Question: {required: true},
File: {required: true},
Reward: {required: true},
Pic: {required: true},
},
showErrors: function(errorMap, errorList) {
$.each(this.successList, function(index, value) {return $(value).popover("hide");});
return $.each(errorList, function(index, value) {
var _popover;
console.log(value.message);//message from popover
_popover = $(value.element).popover({
trigger: "manual",
placement: "right",
content: value.message,
template: "<div class=\"popover\"><div class=\"arrow\"></div><div class=\"popover-inner\"><div class=\"popover-content\"><p></p></div></div></div>"
});
_popover.data("popover").options.content = value.message;
return $(value.element).popover("show");
});
}
});
});
</script>
<!--<script src="http://code.jquery.com/jquery-1.7.min.js" ></script>-->
<script src="bootstrap/FileUpload/bootstrap-fileupload.js" type="text/javascript"></script>
<script type="text/javascript">
function fncCheck(_val){
document.getElementById("CourProj").value="";
if(_val == "CourseProject"){
document.getElementById("CourProj").style.display="";
}
else{
document.getElementById("CourProj").style.display="none";
}
}
</script>
<body>
<!-- head sit -->
<table width="1181">
<tr>
<td width="314" rowspan="3">
<center><img src="Picture/logo.png"/img></center></td>
<td colspan="2">
<center><img src="Picture/head1.png"/img></center></td>
</tr>
<!-- login info -->
<tr>
<td width="751"><div align="right">Welcome, admin</div></td>
<td width="100">
<div align="right"><button type="submit" class="btn" name="submit" value="Submit"/>Logout</div>
</td>
</tr>
<!-- icon -->
<tr>
<td width="751">
<div align="right">
<img height="23" width="23" src="Icon/UploadProj.png">Upload Project</img>
<img height="23" width="23" src="Icon/Register.png"></img>
<a href="Registeration.php" style="text-decoration:none" >Register</a>
<img height="23" width="23" src="Icon/Member.png"> Member</img>
</div>
</td>
<td width="100"></td>
</tr>
</table>
<form method="post" action="saveUpload.php" enctype="multipart/form-data">
<div id="bgr">
<fieldset>
<legend>Upload Project</legend>
<table width="802">
<tr>
<td>Project Name :</td><td><input class="span3" name="Name" type="text" placeholder="Type something"/></td>
</tr>
<tr>
<td>Description :</td><td><input class="span3" name="Description" id="Description" type="text" placeholder="Type something"/></td>
</tr>
<tr>
<td>Platform/Programming :</td><td><select class="span3" name="Language">
<option value="" >Select Platform/Programming</option>
<option value="Android">Android</option>
<option value="Java">Java</option>
</select></td>
</tr>
<tr>
<td>Lecturer/Advisors :</td><td><select class="span3" name="Advisor">
<option value="" >Select Lecturer/Advisors</option>
<option value="A">A</option>
<option value="B">B</option>
</select></td>
</tr>
<tr>
<td>Project Type :</td>
<td><label class="radio">
<input type="radio" name="rdoname" id="rdoname" value="SeniorProject" onclick="fncCheck(this.value);">SeniorProject
</label>
<label class="radio">
<input type="radio" name="rdoname" id="rdoname" value="CourseProject" onclick="fncCheck(this.value);">CourseProject
</label>
<select class="span3" name="CourProj" id="CourProj" style="display:none">
<option value="">Select Project Type</option>
<option value="01">01</option>
<option value="02">02</option>
</select>
</td>
</tr>
<tr>
<td>Project Year :</td><td><select class="span3" name="Year">
<option value="" >Select Year</option>
<option value="1/2013">1/2013</option>
<option value="2/2013">2/2013</option>
</select></td>
</tr>
<tr>
<td>Why is it the showcase :</td><td><input class="span3" name="Question" id="Question" type="text" placeholder="Type something"/></td>
</fieldset>
<tr>
<td>Upload File :</td>
<td><div class="fileupload fileupload-new" data-provides="fileupload">
<div class="input-append">
<div class="uneditable-input span3"><i class="icon-file fileupload-exists"></i><span class="fileupload-preview"></span></div>
<span class="btn btn-file">
<span class="fileupload-new">Select file</span>
<span class="fileupload-exists">Change</span>
<input type="file" name="File"></span><a class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</div>
</td>
</tr>
<tr>
<td>Reward Icon :</td>
<td>
<label class="radio inline">
<input type="radio" name="Reward" id="1" value="Gold"> Gold
</label>
<label class="radio inline">
<input type="radio" name="Reward" id="2" value="Bronz"> Bronz
</label>
<label class="radio inline">
<input type="radio" name="Reward" id="3" value="Metal"> Metal
</label>
</td>
</tr>
<tr>
<td height="90">Project Icon :</td>
<td>
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-new thumbnail" style="width: 50px; height: 50px;">
<img src="http://www.placehold.it/50x50/EFEFEF/AAAAAA" /></div>
<div class="fileupload-preview fileupload-exists thumbnail" style="width: 50px; height: 50px;"></div>
<span class="btn btn-file"><span class="fileupload-new">Select image</span>
<span class="fileupload-exists">Change</span><input type="file" name="Pic"/></span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</td>
</tr>
</table>
<center><button type="submit" name="Submit" value="Save" class="btn btn-info"><i class="iconic-right-quote"></i> Submit</button></center>
<i class="iconic-home"></i>
</form>
<!-- orange bg -->
<style type="text/css">
body {
background-image:url(Picture/Bg.png);
}
</style>
</body>
</html>
saveUpload.php
Code (PHP)
<?
mysql_connect("localhost","root","");
mysql_select_db("csv");
if($_FILES["File"]["name"] != "")
{
//*** Read file BINARY ***'
$fp = fopen($_FILES["File"]["tmp_name"],"r");
$ReadBinary = fread($fp,filesize($_FILES["File"]["tmp_name"]));
fclose($fp);
$FileData = addslashes($ReadBinary);
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("csv");
$strSQL = "INSERT INTO ProjectInfo ";
$strSQL .="(ProjectName,Description,Language,Advisor,ProjectType,CourseName,Year,Question,ProjectFile) VALUES";
$strSQL .="('".$_POST["Name"]."','".$_POST["Description"]."','".$_POST["Language"]."','".$_POST["Advisor"]."','".$_POST["rdoname"]."',
'".$_POST["CourProj"]."','".$_POST["Year"]."','".$_POST["Question"]."','".$FileData."')";
//'".$_POST["Language"]."','".$_POST["Advisor"]."',
//'".$_POST["rdoname"]."','".$_POST["CourProj"]."','".$_POST["Year"]."','".$FileData."',
//'".$_POST["Reward"]."';
//$strSQL .="(ProjectName,Proj,Advisor) VALUES ('".$_POST["Name"]."','".$FileData."','".$_POST["Advisor"]."')";
$objQuery = mysql_query($strSQL);
echo "Copy/Upload Complete<br>";
mysql_close($objConnect);
} else {
echo "cannot uploadfile";
}
?>
Tag : PHP
|
|
|
|
|
|
Date :
2013-06-28 21:56:24 |
By :
mrronalz |
View :
727 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทราบแล้วค่ะ ต้องเปลี่ยนเป็น mediumBlob จาก longBlob คืออยากรู้ว่าทำไมถึงเป็นเช่นนั้นคะ
|
|
|
|
|
Date :
2013-06-28 22:05:21 |
By :
mrronalz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|