Jump to content

Recommended Posts

Hi,there.

 

I am doing on a php photo album.

Here is my table structure for images:

CREATE TABLE `images` (
  `Id` int(11) NOT NULL auto_increment,
  `name` text,
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

I save the images as a path(e.g. http://localhost/album/images/pic.jpg) in field 'name' of table 'images'.

and now i would like to know how to delete the images from both the DB and the directory that i saved the images.

 

Any ideas?

Thanks..

 

Link to comment
https://forums.phpfreaks.com/topic/69162-delete-imagesfilename/
Share on other sites

Hi, shab.

 

I can delete the files from db but then i'm facing with problems when i try to delete files from server.

It shows the error message like below:

Warning: unlink(localhost/album/mall/images/No_2897.jpg) [function.unlink]: No such file or directory

 

I put all my images in  ../album/mall/images/ directory and I've checked that the image is in the directory.

 

Below is my code for deleting images:

<?php 
if (isset($_POST['delete']))
{ 
 $query  = "SELECT * FROM images";
 $result = mysql_query($query)or die(mysql_error());
 $row    = mysql_fetch_array($result);
 $id     = $row['Id']; 
 $path   = "mall/smallthumbnail.php?i=http://localhost/album/mall/images/";
 $name   = $row['name'];  
 $path   = $path.$name;  

 // Delete the record from database.
$query2	 = "DELETE FROM images WHERE Id='$id'";
$result2 = mysql_query($query2)or die(mysql_error());
//delete record from server
unlink($path);
}

?>
<body>
<p align="right"><a href="gallery.php">Back To Gallery</a></p>
<form name="delete" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="id" value="<?php echo $id ?>">
<center>
<img src="<?php echo $path ?>" width="400" height="400"> <br>
<input type="submit" name="delete" value="Delete">
</center>
</form>

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/69162-delete-imagesfilename/#findComment-348169
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.