|
 |
|
คือผมต้องเขียนเกี่ยวกับการแก้ไข ช่วยหน่อยครับ คือมีคนให้คอนเซ็ปมาในการแก้ไขรูปภาพครับ ประมาณว่า |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
if($_FILES["file"]["size"]>0)
{
//ถ้าไฟล์มีค่า ก็สั่งcopy
copy($src_file,$dest_file);
}
?>
|
 |
 |
 |
 |
Date :
2009-03-03 15:44:39 |
By :
aprodise |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ประมาณว่าแบบนี้นะค่ะ
Code
<?
if($_post[Submit]){
if($_POST[upload]!=""){ //ถ้าไม่ว่าง
//แล้วก็ทำการ อัพโหลดรูปภาพเลยค่ะ
//ตรงนี้ก็ update ข้อมูลลง Table และตรงฟิลด์ path รูป เอามาจาก $_POST[upload] ก็คือรูปที่อัพใหม่นั่นเอง
}else{ // ตรงนี้คือถ้าว่าง
//ไม่ต้องอัพโหลดรูป
// update ข้อมูลลง Table โดยไม่ต้อง Update ฟิลด์ path ของรูป
}
}
?>
|
 |
 |
 |
 |
Date :
2009-03-03 15:50:12 |
By :
Jewels |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่เข้าใจอะครับ คือ ฟิวรูป ที่เก็บ path มันก็อยู่รวมกับ ฟิวที่เป็นข้อมูลอื่น ๆ ด้วยอะครับคือจะดึงมาแก้ไขในหน้าเดียวกันอะครับ
<?
$con_db = mysql_pconnect("localhost","root","")or die("ไม่สามารถติดต่อฐานข้อมูลได้");
$db = mysql_select_db("data_student_it_system")or die("ไม่สามารถเลือกฐานข้อมูลได้");
$sql ="SELECT * FROM data_student_it WHERE Id='$Id' ";
$sqlquery = mysql_query($sql);
$result = mysql_fetch_array($sqlquery);
?>
<form name="form1" method="post" action="update_data_student_it.php"enctype="multipart/form-data">
<table width="756" border="1" align="center">
<tr>
<td width="423">รูป :
<label>
</label>
<label></label>
<img src="image_student/<? echo $result["image"];?>" /> <label>
<input type="file" name="upload" />
</label></td>
<td width="104">รหัสนักศึกษา</td>
<td width="7">:</td>
<td width="194"><label>
<input name="student_id" type="text" id="student_id"value="<?=$result['student_id'];?>"/>
</label></td>
</tr>
<tr>
<td>
</td>
<td>ชื่อ</td>
<td>:</td>
<td><label>
<input name="first_name" type="text" id="first_name"value="<?=$result['first_name'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>นามสกุล</td>
<td>:</td>
<td><label>
<input name="last_name" type="text" id="last_name"value="<?=$result['last_name'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>ชื่อเล่น</td>
<td>:</td>
<td><label>
<input name="nick_name" type="text" id="nick_name"value="<?=$result['nick_name'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>วันเกิด</td>
<td>:</td>
<td><label>
<input name="birth_day" type="text" id="birth_day"value="<?=$result['birth_day'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>ที่</td>
<td>:</td>
<td><label>
<input name="birth_date" type="text" id="birth_date"value="<?=$result['birth_date'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>เดือน</td>
<td>:</td>
<td><label>
<input name="birth_month" type="text" id="birth_month"value="<?=$result['birth_month'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>พ.ศ.</td>
<td>:</td>
<td><label>
<input name="birth_year" type="text" id="birth_year"value="<?=$result['birty_year'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>บ้านเลขที่</td>
<td>:</td>
<td><label>
<input name="home_number" type="text" id="home_number"value="<?=$result['home_number'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>หมู่ที่</td>
<td>:</td>
<td><label>
<input name="grouphome_number" type="text" id="grouphome_number"value="<?=$result['grouphome_number'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>ตำบล</td>
<td>:</td>
<td><label>
<input name="point" type="text" id="point"value="<?=$result['point'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>อำเภอ</td>
<td>:</td>
<td><label>
<input name="amper" type="text" id="amper"value="<?=$result['amper'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>จังหวัด</td>
<td>:</td>
<td><label>
<input name="province" type="text" id="province"value="<?=$result['province'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>รหัสไปรษณีย์</td>
<td>:</td>
<td><label>
<input name="zipcode" type="text" id="zipcode"value="<?=$result['zipcode'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>เบอร์โทรศัพท์</td>
<td>:</td>
<td><label>
<input name="number_phone" type="text" id="number_phone"value="<?=$result['number_phone'];?>">
</label></td>
</tr>
<tr>
<td> </td>
<td>email</td>
<td>:</td>
<td><label>
<input name="email" type="text" id="email"value="<?=$result['email'];?>">
</label></td>
</tr>
</table>
<table width="756" border="1" align="center">
<tr>
<td width="422"><label>
<div align="center">
<input name="Id" type="hidden" id="Id" value="<?=$result['Id']?>" />
<input type="submit" name="Submit" value="บันทึก" />
</div>
</label></td>
<td width="318"><label>
<div align="center">
<input type="reset" name="Submit2" value="ยกเลิก" />
</div>
</label></td>
</tr>
</table>
<p></p>
</form>
|
 |
 |
 |
 |
Date :
2009-03-03 16:35:25 |
By :
taknaja |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถูกค่ะ ใช่แล้ว อยู่ table เดียวกัน แต่ถ้าค่าว่าง ก็ไม่ต้องอัพเดต ฟิลด์ที่เก็บ path ไงคะ
ถ้าไม่เข้าในเอา code ตอน update เวลา กดปุ่ม submit แล้ว มาให้ดูหน่อยค่ะ
|
 |
 |
 |
 |
Date :
2009-03-03 16:55:17 |
By :
Jewels |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค๊ดอัพเดทครับ
<?
$con_db = mysql_pconnect("localhost","root","")or die ("ไม่สามารถติดต่อฐานข้อมูลได้");
$db = mysql_select_db ("data_student_it_system") or die("ไม่สามารถเลือกฐานข้อมูลได้");
$image=$_FILES['upload']['name'];
$edit = "UPDATE data_student_it SET student_id='$student_id'
,first_name='$first_name',last_name='$last_name',
nick_name='$nick_name',birth_day='$birth_day',
birth_date='$birth_date',birth_month='$birth_month',
birth_year='$birth_year',home_number='$home_number',
grouphome_number='$grouphome_number',point='$point',
amper='$amper',province='$province',zipcode='$zipcode',
number_phone='$number_phone',email='$email' ,
image ='$image' WHERE Id='$Id' ";
$editquery = mysql_query($edit);
if ($editquery)
{
echo"<script> window.location.href='show_data_student_it.php'; </script> ";
}
else
{
echo "ERROR[".$edit."]";
}
?>
|
 |
 |
 |
 |
Date :
2009-03-03 16:59:51 |
By :
taknaja |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องขออภัย นึกว่ามันเป็น $_POST แต่มันส่งด้วย $_FILE
แค่เช็คว่ามันว่างไหม ถ้าว่างให้เอา ฟิลด์ที่อัพเดต path ออกเท่านั้นเองค่ะ
Code
<?
$con_db = mysql_pconnect("localhost","root","")or die ("ไม่สามารถติดต่อฐานข้อมูลได้");
$db = mysql_select_db ("data_student_it_system") or die("ไม่สามารถเลือกฐานข้อมูลได้");
$image=$_FILES['upload']['name'];
if($_FILES['upload']['tmp_name'] != ""){
$edit = "UPDATE data_student_it SET student_id='$student_id',first_name='$first_name',last_name='$last_name',nick_name='$nick_name',
birth_day='$birth_day',birth_date='$birth_date',birth_month='$birth_month',birth_year='$birth_year',home_number='$home_number',
grouphome_number='$grouphome_number',point='$point',amper='$amper',province='$province',zipcode='$zipcode',number_phone='$number_phone',
email='$email' , image ='$image' WHERE Id='$Id' ";
}else{
$edit = "UPDATE data_student_it SET student_id='$student_id', first_name='$first_name',last_name='$last_name',nick_name='$nick_name',
birth_day='$birth_day',birth_date='$birth_date',birth_month='$birth_month',birth_year='$birth_year',home_number='$home_number',
grouphome_number='$grouphome_number',point='$point',amper='$amper',province='$province',zipcode='$zipcode',number_phone='$number_phone',
email='$email' WHERE Id='$Id' ";
}
$editquery = mysql_query($edit);
if ($editquery)
{
echo"<script> window.location.href='show_data_student_it.php'; </script> ";
}
else
{
echo "ERROR[".$edit."]";
}
?>
|
 |
 |
 |
 |
Date :
2009-03-03 17:15:45 |
By :
Jewels |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมขอคำปรึกษาด้วยครับเรื่องการอัพเดทรูป ผมจะเก็บชื่อพาท ไว้ในดาต้าเบส และเก็บไฟล์รูปไว้ในโฟล์เดอร์ครับ
แต่มีปัญหาตอนเรียกรูปมาแก้ไข
ส่วนโค๊ดนี้เป็นตัวบันทึกข้อมูลต่างๆๆรวมรูปด้วยครับ
Code (PHP)
/* โค๊ดก่อนการอัพรูป*/
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"];
copy($_FILES["fileUpload"]["tmp_name"],"MyResize/".$_FILES["fileUpload"]["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);
$strSQL = "INSERT INTO tbst ";
$strSQL.="(st_num,st_id,st_card,st_mrs,st_fname,st_lname,st_nickname,st_nationality,st_nr,st_brday,st_address,st_level,st_age,income,ft_name,mt_name,fmt_address,fmt_tel,fmt_work,Thumbnails,FilesName) ";
$strSQL.="VALUES ";
$strSQL.="('$stnum','$txtstid','$txtid_cade','$fmail','$txtname','$txtlastname','$txtnickname','$nationalit','$nr','$brday','$address1','$level','$age','$txtincome','$nameft','$namest','$addresst','$tel','$work','".$new_images."','".$_FILES[
"fileUpload"]["name"]."')";
แล้วตอนแก้ไขผมมั่วๆๆเอาอ่ะครับ
Code (PHP)
/* โค๊ดก่อนการอัพรูป*/
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"];
copy($_FILES["fileUpload"]["tmp_name"],"MyResize/".$_FILES["fileUpload"]["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);
//$image=$_FILES['fileUpload']['tmp_name'];
$num=5300007 ;
$strSQL = "UPDATE tbst Set ";
$strSQL.="(Thumbnails,FilesName) ";
$strSQL.="VALUES ";
$strSQL.="('".$new_images."','".$_FILES["fileUpload"]["name"]."')where st_id='$num'";
$objQuery = mysql_query($strSQL)or die (mysql_error());
ช่วยผมด้วครับ
|
 |
 |
 |
 |
Date :
2010-02-20 13:21:32 |
By :
น้องใหม่ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|