mdvignesh Posted February 5, 2012 Share Posted February 5, 2012 Help me. What I am doing is editing a form with checkboxes... and updating image .. I uploaded scripts I want to delete old jpeg file from thumb folder and update new filename in db <!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> <script type="text/javascript"> function show_confirm() { var r=confirm("Delete?"); if (r==true) { //javascript:window.location='view.php'; alert("Deleted!!"); } else { //javascript:window.location='view.php'; alert("You pressed Cancel!"); return false; } } </script> </head> <body> <?php require("connect.php"); if ($_REQUEST['submit']) { $id=$_POST['hide']; for($i=1; $i<=$id; $i++) { $query2 = mysql_query("SELECT * from stu_detail WHERE id = $id "); while($file = mysql_fetch_array($query2)) { $unlink = unlink("up_images/thumb/" . $file['filename']); } } $new_name=$_POST['name']; $new_email=$_POST['email']; $new_phone=$_POST['phone']; $new_gender=$_POST['rad']; $new_city=$_POST['city']; $new_lang=implode(",",$_POST['chk']); $tar = "c:/wamp/www/rms/vignesh_2/up_images/"; if ($_FILES['efile']['error'] > 0) echo "Error" . $_FILES["efile"]["error"]; else { if (file_exists ("$tar" . $_FILES['efile']['name'])) { echo $_FILES['efile']['name'] . " already exsists"; } else { move_uploaded_file ($_FILES['efile']['tmp_name'],"$tar" . $_FILES['efile']['name']); } } $qry=mysql_query("UPDATE stu_detail SET name='".$new_name."', email='".$new_email."', phone='".$new_phone."', gender='".$new_gender."', city='".$new_city."', lang='".$new_lang."', filename='".$_FILES['efile']['name']."' WHERE id=$id ") or die(mysql_error()); require_once("create_thumb.php"); echo generateThumbs(); if (!$qry) { echo "not updated"; } else { echo "<table align='center' border='1' width='800' height='600'>"; ?><tr> <th scope="col">Name</th> <th scope="col">E-mail Address</th> <th scope="col">Phone</th> <th scope="col">Gender</th> <th scope="col">City</th> <th scope="col">Language</th> </tr> <?php $recyc=mysql_query("SELECT * FROM stu_detail where status = 1") or die(mysql_error()); $del = mysql_num_rows($recyc); if ($del != 0) echo "<a href='recycled.php'>Recycle bin</a>"; if ($qry2=mysql_query("SELECT * FROM stu_detail where status = 0 order by id desc") ) { while($res=mysql_fetch_array($qry2)) { ?> <tr> <td><?php echo $res['name']; ?></td> <td><?php echo $res['email']; ?></td> <td><?php echo $res['phone']; ?></td> <td><?php echo $res['gender']; ?></td> <td><?php echo $res['city']; ?></td> <td><?php echo $res['lang']; ?></td> <td> <img src="up_images/thumb/<?php echo $res['filename']; ?>" /> </td> <td> <a href="edit.php?uid=<?php echo $res['id']; ?>">edit</a></td> <!--<td><button type="button" onClick="return show_confirm();">Delete</button> </td>--> <td> <a href="delete.php?uid=<?php echo $res['id']; ?>" onClick="return show_confirm();">delete</a></td> </tr> <?php } } ?> </table> <?php } } ?> </body> </html> 17500_.php 17501_.php Quote Link to comment https://forums.phpfreaks.com/topic/256448-delete-image-from-folder-in-upating/ Share on other sites More sharing options...
litebearer Posted February 5, 2012 Share Posted February 5, 2012 IF you have only two images per user (full and thumb) the easiest way is to simply overwrite the old image with the new image by saving the new image using the old name. Quote Link to comment https://forums.phpfreaks.com/topic/256448-delete-image-from-folder-in-upating/#findComment-1314738 Share on other sites More sharing options...
mdvignesh Posted February 5, 2012 Author Share Posted February 5, 2012 thank u very much but how to overwrite Quote Link to comment https://forums.phpfreaks.com/topic/256448-delete-image-from-folder-in-upating/#findComment-1314744 Share on other sites More sharing options...
digibucc Posted February 5, 2012 Share Posted February 5, 2012 by using GD's imggif, imgjpeg, or imgpng to write it to a file. http://www.php.net/manual/en/function.imagejpeg.php http://www.php.net/manual/en/function.imagegif.php http://www.php.net/manual/en/function.imagepng.php Quote Link to comment https://forums.phpfreaks.com/topic/256448-delete-image-from-folder-in-upating/#findComment-1314770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.