 |
บันทึกรูปไม่ได้ครับ พอสั่งบันทึกจะขึ้น Upload unsuccessfull! ช่วยด้วยครับ |
|
 |
|
|
 |
 |
|
พอสั่งบันทึกจะขึ้น Upload unsuccessfull! ช่วยด้วยครับ ตอนแรกก็ทำงานปกติดีครับ
Code (PHP)
<?
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","100");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image){
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else {
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error
//if ($size > MAX_SIZE*1024){
//echo '<h1>You have exceeded the size limit!</h1>';
//$errors=1;
//}
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<center><h4>Upload unsuccessfull!</h4></center>';
$errors=1;
}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
//echo "<center><h1>File Uploaded Successfully! Try again!</h1></center>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","maenamburi_user","415236") or die("Error Connect to Database");
$objDB = mysql_select_db("maenamburi_user");
$strSQL = "INSERT INTO manamburi_files ";
$strSQL .="(Thumbnails,FilesName) VALUES ('".$image_name."','".$image_name."')";
$objQuery = mysql_query($strSQL);
}
// for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
// {
// if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")
// {
// $images = $_FILES["fileUpload"]["tmp_name"][$i];
// $new_images = "Thumbnails_".$_FILES["fileUpload"]["name"][$i];
// copy($_FILES["fileUpload"]["tmp_name"][$i],"MyResize/".$_FILES["fileUpload"]["name"][$i]);
// $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);
//
//
//
// //*** Insert Record ***//
// $objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
// $objDB = mysql_select_db("starz_db");
// $strSQL = "INSERT INTO files ";
// $strSQL .="(Thumbnails,FilesName) VALUES ('".$new_images."','".$_FILES["fileUpload"]["name"][$i]."')";
// $objQuery = mysql_query($strSQL);
// }
// }
//
?>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-01-11 11:08:46 |
By :
boy415 |
View :
1437 |
Reply :
21 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ติดอยู่ที่บรรทัดที่ 056 อะครับช่วยหน่อยครับ
|
 |
 |
 |
 |
Date :
2010-01-11 12:32:22 |
By :
boy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ทราบว่ารูปที่ copy ไปหรือยัง
ลอง echo $copied ดูค่าของมันก่อนนะคะ
|
 |
 |
 |
 |
Date :
2010-01-11 13:37:37 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองตาม ที่ ultrasiam ลองสั่ง echo $copied ผลลัพธ์ แสดง Scopied ครับ
|
 |
 |
 |
 |
Date :
2010-01-11 14:30:48 |
By :
boy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

Code (PHP)
<?
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","100");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image){
//get the original name of the file from the clients machine
echo"$image<BR>";/* ดูชื่อรูปที่จะเก็บ */
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
echo"$filename<BR>";/* ดูชื่อรูปที่จะเก็บ */
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else {
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error
//if ($size > MAX_SIZE*1024){
//echo '<h1>You have exceeded the size limit!</h1>';
//$errors=1;
echo"$size<BR>";/*ขนาดไฟล์*///}
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
echo"$image_name<BR>";/*ชื่อไฟล์รูปที่จะเก็บลงไฟล์ images*/
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
echo"$newname";/*ชื่อใหม่ที่จะเก็บไว้ในโฟล์เดอร์ images*/
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<center><h4>Upload unsuccessfull!</h4></center>';
$errors=1;
}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
//echo "<center><h1>File Uploaded Successfully! Try again!</h1></center>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","maenamburi_user","415236") or die("Error Connect to Database");
$objDB = mysql_select_db("maenamburi_user");
$strSQL = "INSERT INTO manamburi_files ";
$strSQL .="(Thumbnails,FilesName) VALUES ('".$image_name."','".$image_name."')";
$objQuery = mysql_query($strSQL);
}
ช่วยผมด้วยครับ ผมลองอัพขึ้นแล้วมันไม่สามารถเก็บรูปได้ครับ แต่ผมลองเทสอีกโฮตหนึ่ง เก็บได้น่ะครับม่ายรู้เป็นไรครับช่วยด้วยครับ ผมลอง echo ดูมาติดตอนที่ $copied = copy($_FILES['image']['tmp_name'], $newname); ตรงนี้ครับ ช่วยหน่อยครับ
|
 |
 |
 |
 |
Date :
2010-01-11 16:41:33 |
By :
boy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มี error อะไรขึ้นมาหรือเปล่าคะ
แล้วค่าที่ echo ได้ค่าอะไร
สู้ ๆ ค่ะ
|
 |
 |
 |
 |
Date :
2010-01-11 16:51:15 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่มี error นะครับผมลอง echo ของแต่ละตัวแปรได้ค่า เหมือนรูปด้านบนมุมซ้าย ของรูปอ่ะครับ แล้วจะมาติดอยู่กะตัว $copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<center><h4>Upload unsuccessfull!</h4></center>';
$errors=1;
มันติดอยู่ตรงนี้อ่ะครับ เหมือนไม่สามารถที่จะก๊อฟปี้ไฟล์ ไปไว้ในไฟล์ images ได้อะครับ ค่าของ $copied
แก้ทั้งวันแล้วครับ งงง ช่วยด้วยครับ
|
 |
 |
 |
 |
Date :
2010-01-11 18:43:05 |
By :
ิboy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<form method="post" action="<? $PHP_SELF; ?>" enctype="multipart/form-data">
รูปภาพ:<input type="file" name="picture">
<br><br>
<input type="submit" value="ตกลง" name="send">
<input type="reset" value="ยกเลิก" name="cancle">
</div>
</form>
<?
if($_REQUEST['send']){
$picture=$_FILES["picture"]["tmp_name"];
$filename=$_FILES["picture"]["name"];
$path="images/"; //folder ของคุณ
$image=$path.$filename;
if(copy($picture,$image)){
echo "อัพโหลดสำเร็จแล้ว<p>";
}else{
echo "ไม่สามารถอัพโหลดได้<p>";
}
}
ลองเอาโค้ดนี้ไปรันดูก่อนนะคะว่าติดอะไรไหม ถ้าใช้งานได้ลองเอาโค้ดอัพโหลดนี้ไปปรับใช้ดูนะคะ
|
 |
 |
 |
 |
Date :
2010-01-11 19:32:43 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ นะครับ คุณ ultrasiam ผมลองดูก่อนน่ะครับ เดี่ยวมารายงานผลครับ
|
 |
 |
 |
 |
Date :
2010-01-11 20:23:37 |
By :
ิboy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดี่คุณ ultrasiam หัยใช้ได้น่ะคราบ
ลองแต่งปรับดูคราบ
|
 |
 |
 |
 |
Date :
2010-01-11 20:32:13 |
By :
parita |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค๊ดที่คุณ ultrasiam ไม่ได้ครับ ยังไม่ได้เลยครบ
|
 |
 |
 |
 |
Date :
2010-01-11 21:31:42 |
By :
boy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือเอาไปสร้างไฟล์ใหม่แล้วลองรันดูเลยนะคะ ไม่ได้เลยหรอ ลองแล้ว copy file ได้นะคะ
เป็นโค้ดที่ปรับจากของคุณ T ที่ให้คุณคนนึงไปใช้เมื่อเช้า เค้าก็ใช้ได้
คืออยากให้คุณลองแค่ copy file ก่อนยังไม่ต้องสนตัวอื่น ดูว่า เครื่องคุณ copy file ได้หรือเปล่า
|
 |
 |
 |
 |
Date :
2010-01-11 21:47:15 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตามที่คุณ ultrasiam ได้น่ะครับ ผมลองสร้างไฟล์ตามที่คุณบอก ก๊อฟปี้ได้ครับ แล้วถ้าจะนำไปใช้ล่ะครับ แทรกกับโค๊ดด้านบนต้องทำไงครบ
|
 |
 |
 |
 |
Date :
2010-01-11 23:01:05 |
By :
boy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ผมได้ทำตามที่คุณ ultrasiam บอกแล้วน่ะครับ และผมได้แทรกไปไว้ที่โค๊ดด้านบน
Code (PHP)
<?
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","100");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
$image=$_FILES['image']['name'];
//if it is not empty
if ($image){
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else {
$size=filesize($_FILES['image']['tmp_name']);
echo"size.$size<BR>";
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
echo"image_name:$image_name<BR>";
$newname="images/".$image_name;
//we verify if the image has been uploaded, and print error instead
echo"newname:$newname<BR>";
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<center><h4>Upload unsuccessfull!</h4></center>';
$errors=1;
}}}}
echo"copied:$copied<BR>";
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
//echo "<center><h1>File Uploaded Successfully! Try again!</h1></center>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","maenamburi_user","415236") or die("Error Connect to Database");
$objDB = mysql_select_db("maenamburi_user");
$strSQL = "INSERT INTO manamburi_files ";
$strSQL .="(Thumbnails,FilesName) VALUES ('".$image_name."','".$image_name."')";
$objQuery = mysql_query($strSQL);
}
?>
<body><br><br>
<center>
<div class="view-pic">
<?php
include("../scripts/ConnectDB.php");
if (!$link)
echo "ERROR MYSQL";
else
{
mysql_select_db($DBName,$link);
$strSQL = "SELECT * FROM manamburi_files";
$result = mysql_query("SELECT * FROM manamburi_files order by FilesID desc");
$Num_Rows = mysql_num_rows($result);
$Per_Page = 27; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$strSQL .=" order by FilesID desc LIMIT $Page_Start , $Per_Page";
$result = mysql_query($strSQL);
?>
<div class="pirobox_min">
<?
while($row = mysql_fetch_array($result))
{
$FilesID=$row['FilesID'];
?>
<span class="img-wrap"><a href="images/<?=$row["FilesName"];?>" class="thickbox" rel="images" >
<img src="images/<?=$row["Thumbnails"];?>" width="80px" height="80px"/>
</a>
<?
echo "<a href='del.php?FilesID=$FilesID')' onclick='del()'>Del</a>"
?>
</span>
<?
}
echo "<div class='h8'>";
//echo "<div class='h8'> PAGE ".$Page." OF " .$Num_Pages." :: GO TO PAGE :: ";
if($Prev_Page)
{
echo "<a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&FilesID=$FilesID' > << PREVIOUS </a>";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "<a href='$_SERVER[SCRIPT_NAME]?Page=$i&FilesID=$FilesID' > $i </a>";
}
else
{
echo " ".$i." ";
}
}
if($Page!=$Num_Pages)
{
echo "<a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&FilesID=$FilesID'> NEXT >> </a>";
}
echo "</div>";
}
mysql_close($link);
?>
</div>
<br><br>
<center>
<!--
<div id="form">
<form name="newad" method="post" enctype="multipart/form-data" action="">
-->
<form method="post" action="<? $PHP_SELF; ?>" enctype="multipart/form-data">
รูปภาพ:<input type="file" name="image">
<br><br>
<input type="submit" value="ตกลง" name="send">
<input type="reset" value="ยกเลิก" name="cancle">
</div>
</form>
<table>
<tr><td> <!--
<input type="file" name="image" class="browse">
<input name="Submit" type="submit" value="Upload" class="up"></td></tr>
-->
<?
if($_REQUEST['send']){
$picture=$_FILES["image"]["tmp_name"];
$filename=$_FILES["image"]["name"];
$path="images/"; //folder ของคุณ
$image=$path.$filename;
if(copy($picture,$image)){
echo "อัพโหลดสำเร็จแล้ว<p>";
}else{
echo "ไม่สามารถอัพโหลดได้<p>";
}
}
?>
<tr><td>
</td></tr>
</table>
</form>
</div>
</center>
แต่ก็ยังไม่สามารถบันทึกลงดาต้าเบสได้น่ะครับ
|
 |
 |
 |
 |
Date :
2010-01-11 23:18:12 |
By :
boy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวอย่างที่ให้ไปไม่ได้มีการบันทึกลง db นี่คะ แค่อยากให้คุณลองว่า copy ได้หรือเปล่า เพราะคุณบอกว่าติดที่ copy
ตกลง copy file ได้แล้วใช่ไหมคะ
ถ้าต้องการบันทึกลงฐานข้อมูล แทรกโค้ดบันทึกไว้ใน if นี้ค่ะ
Code (PHP)
if(copy($picture,$image)){
echo "อัพโหลดสำเร็จแล้ว<p>";
}
ลองดูค่ะ
|
 |
 |
 |
 |
Date :
2010-01-12 08:37:38 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
if($_REQUEST['send']){
$picture=$_FILES["image"]["tmp_name"];
$filename=$_FILES["image"]["name"];
$path="images/"; //folder ของคุณ
$image=$path.$filename;
if(copy($picture,$image)){
$objConnect = mysql_connect("localhost","root","415236") or die("Error Connect to Database");
$objDB = mysql_select_db("maenamburi_user");
$strSQL = "INSERT INTO manamburi_files ";
$strSQL .="(Thumbnails,FilesName) VALUES ('".$picture."','".$image."')";
$objQuery = mysql_query($strSQL);
echo "อัพโหลดสำเร็จแล้ว<p>";
}else{
echo "ไม่สามารถอัพโหลดได้<p>";
}
?>
เก็บลงดาต้าเบสไม่ได้เรยครับ แ
|
 |
 |
 |
 |
Date :
2010-01-12 14:38:57 |
By :
boy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอายังไงดีล่ะทีนี้
ตกลงตอนนี้ copy รุปได้แล้วใช่ไหมคะ แต่ว่าบันทึกลงฐานข้อมูลไม่ได้เนาะ
แล้วคุณต้องการเก็บไฟล์รูปลงฐานข้อมูลเลย หรือแค่เก็บชื่อไฟล์คะ
เห็นคุณเก็บ $picture ด้วย
$strSQL .="(Thumbnails,FilesName) VALUES ('".$picture."','".$image."')";
|
 |
 |
 |
 |
Date :
2010-01-12 14:59:48 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้บันทึกลงดาต้าเบสได้แล้วน่ะแต่ยังผิดอยู่
1 images/006.jpg
2 images/006.jpg
สั้งบันทึกครั้งเดี่ยวดันมาสองตัวเรย แถมตัว images มันติดมาด้วยครับ
ผมเก็บไฟล์รูป ไว้ใน ไฟล์ images ครับ แล้วเก้บ ชื่อไฟล์ในดาต้าเบสครับ
|
 |
 |
 |
 |
Date :
2010-01-12 15:29:37 |
By :
boy415 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เก่งกันจังเลย
ผมก็เป็นแต่ที่คุน ๆ บอกวิธีมาอ่ะ
ผมละอึ้น จิง ๆ
ไม่รุ้จะไปเริ่มตรงไหน
ทำอะไรเกี่ยวกับ รูปไม่ค่อยได้
ค้างลูกเดียว
- -
ทำใจอ่ะ
|
 |
 |
 |
 |
Date :
2010-07-28 23:00:08 |
By :
ApachaFone- |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|