Jump to content

delete image from folder in upating


mdvignesh

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/256448-delete-image-from-folder-in-upating/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.