|
 |
|
ช่วยเชคหน่อย ไม่รู้ผิดตรงไหน อัพรูปได้ แต่ id รูปไม่มา มันมาแค่เนี้ย _13648040501.jpg ที่จริงมันต้องเป็น 1_13648040501.jpg |
|
 |
|
|
 |
 |
|
ช่วยเชคหน่อย ไม่รู้ผิดตรงไหน อัพรูปได้ แต่ id รูปไม่มา มันมาแค่เนี้ย _13648040501.jpg ที่จริงมันต้องเป็น 1_13648040501.jpg
Code
function edit_img(id,id2,images){
var span=document.getElementById(id).innerHTML='<input name="file_edit[]" type="file" id="file['+id2+']" style="width:300px" value"+images+"/>'
+'<input type="text" name="index[]" id="index['+id2+']" value="'+id2+'"><br><br>';
}
<a href="javascript:;" onclick="edit_img('id_$id','$id','$img')">Edit</a> |
Code (PHP)
// [Function upload_images]
function upload_image($img_id,$count,$id,$p=''){
if($name=$img_id['name'][$count]){
$name=$img_id['name'][$count];
$type=$img_id['type'][$count];
$tmp=$img_id['tmp_name'][$count];
$error=$img_id['error'][$count];
$ext = strrchr($name, '.');
$new_name=$id.'_'.time().$count.$ext;
list($w,$h)=getimagesize($tmp);
if($error==0){
if($w!=462&&$h!=602){
echo "<script>alert('Image size 462x602 px only');</script>";
exit;
}
if(!move_uploaded_file($tmp,'../uploads/'.$new_name)){
echo "<script>alert('Can't upload image');</script>";
exit;
}else{
$tn_image = new Thumbnail('../uploads/'.$new_name,300, 200, 0,200);
$tn_image->save('../uploads/thumb_'.$new_name);
}
}
return $p.$new_name;
}
}
// [Edit images only]
$images='';
for($i=0;$i<count($_FILES['file_edit']['name']);$i++)
{
if($_FILES['file_edit']['name'][$i]!=="")
{
$sql_Edits="SELECT * FROM tb_product_image WHERE id_image='".$_POST['index'][$i]."'";
$rs=mysql_query($sql_Edits) or die (mysql_error());
$rec=mysql_fetch_assoc($rs);
$images=$rec['images'];
if($_FILES['file_edit']['name'][$i] !=="")
{
unlink('../uploads/thumb_'.$images);
unlink('../uploads/'.$images);
echo $sql_Edits."<br>";
echo "id_product".$id_product;
/*$imgs=upload_image($_FILES['file_edit'],$i,$_GET['id']);
echo "<script>alert('$imgs')</script>";
$sql_update="update tb_product_image set images='$imgs' WHERE id_image='".$_POST['index'][$i]."' ";
$rs=mysql_query($sql_update) or die (mysql_error());*/
}
}
}
Output
SELECT * FROM tb_product_image WHERE id_image=''
Output
SELECT * FROM tb_product_image WHERE id_image=''
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2013-04-01 16:42:32
|
 |
 |
 |
 |
Date :
2013-04-01 16:39:40 |
By :
nottpoo |
View :
731 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$id มีค่ามาหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2013-04-02 12:08:49 |
By :
Manussawin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|