|
|
|
การอัพโหลดรูปภาพแล้วชื่ออัลบั้มไม่ลงฐานข้อมูลช่วยดูให้อีกนิดค่ะว่าขาดอะไรไปทำไมถึงไม่ได้ |
|
|
|
|
|
|
|
Code (upload)
<!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=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" href="../uploadify/uploadify.css" type="text/css" />
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.uploadify.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#fileUpload2").fileUpload({
'uploader': '../uploadify/uploader.swf',
'cancelImg': '../uploadify/cancel.png',
'script': '../js/uploadify.php',
'folder': '../MyResize/',
'multi': true,
'buttonText': 'Browse..',
'checkScript': '../uploadify/check.php',
'displayData': 'speed',
'simUploadLimit': 2
});
});
</script>
</head>
<body>
<form name="F1" action="javascript:$('#fileUpload2').fileUploadStart()" method="post" enctype="multipart/form-data">
<table width="574" border="0" align="center" cellpadding="1" cellspacing="1" class="FontThai">
<tr>
<td colspan="2" bgcolor="#0099FF"><center><font color="#ffffff">เพิ่มรูปกิจกรรม</font></center></td>
</tr>
<tr>
<td height="121" ><fieldset style="border: 1px solid #CDCDCD; padding: 8px; padding-bottom:0px; margin: 8px 0">
<legend><strong>อัพโหลดรูปกิจกรรม</strong></legend>
<br />
<div id="fileUpload2">You have a problem with your javascript</div>
<p>
<h>อัลบั้มกิจกรรม:
<?
include("connect.php");
$SQL_category = mysql_query("SELECT album_name,album_id FROM album ORDER BY album_name") or die(mysql_error());
echo "<select name=\"album_id\" onChange=\"MM_jumpMenu('parent',this,0)\" class=\"SELECT\">";
echo "<option selected>เลือกอัลบั้มกิจกรรม</option>";
while ($row = mysql_fetch_array($SQL_category)){
$album_name = $row["album_name"];
$album_id = $row["album_id"];
echo "<option value=\"$album_id\">$album_name</option>";
}
echo "</select>";
?>
</h>
<br />
<a href="javascript:$('#fileUpload2').fileUploadStart()">Start Upload</a> | <a href="javascript:$('#fileUpload2').fileUploadClearQueue()">Clear Queue</a></p>
</fieldset></p></td>
</tr>
</table>
</form>
</body>
</html>
Code (uploadify)
<?
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
if(trim($_FILES["Filedata"]["tmp_name"]) != "")
{
$images = $_FILES["Filedata"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["Filedata"]["name"];
copy($_FILES["Filedata"]["tmp_name"],"../MyResize/".$_FILES["Filedata"]["name"]);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImageJPEG($images_fin,"../MyResize/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
echo "Resize and Upload Successful.<br>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
$objDB = mysql_select_db("gallery");
$strSQL = "INSERT INTO picture ";
$strSQL .="(Thumbnails,PicName,album_id) VALUES ('".$new_images."','".$_FILES["Filedata"]["name"]."','$album_id')";
$objQuery = mysql_query($strSQL);
}
move_uploaded_file($tempFile,$targetFile);
echo "1";
}
?>
จากโค๊ดด้านบนสามารถอัพโหลดรูปลงได้
แต่ในการอัพโหลดแต่ละครั้งเราจะกำหนดอัลบั้มให้ด้วย
แต่พอเราอัพโหลดแล้วอัลบั้มไม่สามารถเก็บเข้าฐานข้อมูลได้ แยกอัลบั้มไม่ได้
Tag : PHP, JavaScript, Ajax
|
|
|
|
|
|
Date :
2010-10-04 12:31:24 |
By :
nongjar |
View :
869 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PageMultiUploadToMySQL1.php
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
<script language="javascript">
function fncCreateElement(){
var mySpan = document.getElementById('mySpan');
var myElement1 = document.createElement('input');
myElement1.setAttribute('type',"file");
myElement1.setAttribute('name',"filUpload[]");
}
</script>
</head>
<body>
<form name="frmMain" method="post" action="PageMultiUploadToMySQL2.php" enctype="multipart/form-data">
<input type="file" name="filUpload[]">
<br>
<span id="mySpan"></span>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
PageMultiUploadToMySQL2.php
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("datasps");
for($i=0;$i<count($_FILES["filUpload"]["name"]);$i++)
{
if($_FILES["filUpload"]["name"][$i] != "")
{
if(copy($_FILES["filUpload"]["tmp_name"][$i],"myfile/".$_FILES["filUpload"]["name"][$i]))
{
//*** Insert Record ***//
$strSQL = "INSERT INTO employee ";
$strSQL .="(Em_Pic) VALUES ('".$_FILES["filUpload"]["name"][$i]."')";
$objQuery = mysql_query($strSQL);
}
}
}
echo "Copy/Upload Complete<br>";
?>
<a href="PageMultiUploadToMySQL3.php">View files</a>
</body>
</html>
PageMultiUploadToMySQL3.php
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("datasps");
$strSQL = "SELECT * FROM employee";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
echo"<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"><tr>";
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
echo "<td>";
?>
<table width="91" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><a href="myfile/<?=$objResult["Em_Position"];?>" target="_blank"><img src="myfile/<?=$objResult["Em_Position"];?>" width="100" height="100" border="0"></a></div></td>
</tr>
</table>
<?
echo"</td>";
if(($intRows)%2==0)
{
echo"</tr>";
}
else
{
echo "<td>";
}
}
echo"</tr></table>";
?>
<?
mysql_close($objConnect);
?>
</body>
</html>
ลองเอาไปประยุกต์ดูครับ ไมู้ถูกใจป่าว ผมก็เอาโค้ดเขามาประยุกต์อีกที
|
|
|
|
|
Date :
2010-10-04 12:45:04 |
By :
กร |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แบบว่าอัพโหลดได้
ชื่อรูป ชื่อ thumbnais สามารถเข้าในฐานข้อมูลได้
แต่ชื่ออัลบัมที่เราเก็บมานไม่เข้าในฐานข้อมูลอ่ะค่ะ
ช่วยดูให้หน่อยค่ะ
|
|
|
|
|
Date :
2010-10-04 13:05:31 |
By :
nongjar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|