Jump to content

Recommended Posts

ok, so this is my code

<?php
mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error());
				$qu = "SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'";
				$res = mysql_query($qu) or die ("Error:" . mysql_error());
				$r = mysql_fetch_assoc($res);
				$myFile = "../images/".$r['filename'];
				$fh = fopen($myFile, 'w') or die("can't open file");
				fclose($fh);
				$filename = $r['filename'];
				unlink($filename);
?>

 

but it is trying to delete the image from admin_area.php, not the folder  is ay any ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/
Share on other sites

you have to select it before you delete it...also, you build the filename, then overwrite it...

 

<?php
$res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error());
$r = mysql_fetch_assoc($res);
mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error());
$myFile = "../images/".$r['filename'];
unlink($myFile) or die("can't open file");
?>

try this:

<?php
$res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error());
$r = mysql_fetch_assoc($res);
mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error());
$myFile = "../images/".$r['filename'];
if(!file_exists($myFile)) die("File doesn't exist: '{$myFile}'");
if(!is_writable($myFile)) die("File isn't writable: '{$myFile}'");
unlink($myFile) or die("Can't delete file: '{$myFile}'");
?>

 

What is the output from that?

Warning: unlink(/images/) [function.unlink]: No such file or directory in ....

i get that error with this code

 

$res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error());
				$r = mysql_fetch_assoc($res);
				mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error());
				$myFile = "/images/".$r['filename'];
				unlink($myFile) or die("can't open file");

ah...so the filename column doesn't have a value in it? or it's not finding the row. what is the value of $checked?

 

try this out, it will skip entries without a filename specified...

<?php
$res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error());
$r = mysql_fetch_assoc($res) or die("No entry found");
mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error());
if(strlen($r['filename'])){
  $myFile = "../images/".$r['filename'];
  if(!is_file($myFile)) die("File doesn't exist: '{$myFile}'");
  unlink($myFile) or die("Can't delete file: '{$myFile}'");
}
?>

ok, this one seems to work

			$res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error());
			$r = mysql_fetch_assoc($res);
			mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error());
			$myFile = "images/".$r['filename'];
			if(!file_exists($myFile)) die("File doesn't exist: '{$myFile}'");
			if(!is_writable($myFile)) die("File isn't writable: '{$myFile}'");
			unlink($myFile) or die("Can't delete file: '{$myFile}'");

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.