Page 1 of 1
Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 10:55 am
by cap2cap10
hello, php Technorati. Here I am again, banging my head on another perplexing issue. Here is my code:
Code: Select all
<center><form method=POST action=delete_pic.php >
<input type=hidden name=submitting value=true />
<input type=submit name=submitting value="Delete My Photo!" >
</form></center>
<?
$tdir = "uploads/thumbs/"; // Path To Thumbnails Directory<-- yes, this is the correct path!!!!
$url= $_GET['url']<-- yes, this works!!
if (isset($_POST['submitting'])) {
$image_name= $url ;
mysql_connect(*******************************) or die(mysql_error());
mysql_select_db('**********) or die(mysql_error());
mysql_query("DELETE $image_name FROM js_resume WHERE candidateID ='$candidateID'") or die(mysql_error());
$query = "UPDATE js_resume SET pic_stat = 'no' WHERE candidateID = '$candidateID'";
$result = mysql_query($query) or die(mysql_query());
mysql_close();
@unlink("$tdir" . $url);
echo'<span class="style2">Your photo has been deleted! Click <a href=" ag_upload_pic.php" title="Please Reupload Photo!">HERE</a> to reupload photo!</span>';
}
?>
It refuses to delete the image file from the directory!?!
Will someone please enlighten me??
Thanks in advance,
Batoe
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 11:00 am
by AbraCadaver
Why don't you turn on error reporting and get rid of the @ in the unlink() so you can actually get the error?
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 11:04 am
by cap2cap10
ok, this was the error:
Warning: unlink(uploads/thumbs/) [function.unlink]: Is a directory in
any ideas?
Thanks in advance,
Batoe
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 11:09 am
by AbraCadaver
cap2cap10 wrote:ok, this was the error:
Warning: unlink(uploads/thumbs/) [function.unlink]: Is a directory in
any ideas?
Thanks in advance,
Batoe
Yes, $url is empty.
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 11:22 am
by cap2cap10
Ok, are you saying that the unlink command worked or the directory that it goes to is empty and maybe the wrong directory? Im getting dizzy
Batoe
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 11:59 am
by AbraCadaver
What I'm saying is that, I can see in your code that: $tdir = "uploads/thumbs/" and you are trying to unlink($tdir . $url) and the error is that uploads/thumbs is a directory and can't be deleted, so that means that the variable $url doesn't contain anything.
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 1:17 pm
by cap2cap10
Ok, I see what you are saying. The variable $url contains the file name but not the path and since the image file is in a different directory, unlink cannot locate the image file! So how do I get $url to include the directory path?
I tried connecting it with $tdir :
$urls = $tdir.$url <-- but it does not work
How should the unlink statement look like?
Thanks for your patience,
Batoe
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 1:19 pm
by AbraCadaver
AbraCadaver wrote:What I'm saying is that, I can see in your code that: $tdir = "uploads/thumbs/" and you are trying to unlink($tdir . $url) and the error is that uploads/thumbs is a directory and can't be deleted, so that means that the variable $url doesn't contain anything.
What did this output?
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 3:15 pm
by cap2cap10
I am not sure if I did this correctly but here goes:
unlink(echo $tdir . $url;);
Error-Parse error: syntax error, unexpected T_ECHO, expecting ')'
Was I wrong?
Thanks again,
Batoe
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 3:26 pm
by AbraCadaver
Just do what I posted. Don't put it in the unlink(). The point is that $url is empty, there is no value in it. The reason is that there is no $_GET['url'].
Also, put this at the top of all of your files while you are developing:
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', '1');
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 4:05 pm
by cap2cap10
ok, I think I steered you into the wrong direction. The $_GET['url'] is present, but it is at the top of the script.
I know it works because the delete.php page shows the image that will be deleted via $url. Sorry for the misunderstanding. here is the whole script that shows the image and the delete button:
Code: Select all
<?php
$idir = "uploads/"; // Path To Images Directory
$tdir = "uploads/thumbs/"; // Path To Thumbnails Directory
$url = $_GET['url']
if ($url) {
$imagelocation = 'uploads/thumbs/'.$url.'';
$imagesize = getimagesize($imagelocation);
$width = .99 * $imagesize['0'];
$height = .99 * $imagesize['1'];
echo '<img src = "'.$imagelocation.'" height="'.$height.'" width="'.$width.'">';
}
elseif("$url == ''")
{
print " <img src=images/nopic.jpg width=100 height=130 border=0 alt=NO PHOTO!> ";
}
?></center> <P>
<center><form method=POST action=delete_pic.php >
<input type=hidden name=submitting value=true />
<input type=submit name=submitting value="Delete My Photo!" >
</form></center>
<?php
$tdir = "uploads/thumbs"; // Path To Thumbnails Directory
if (isset($_POST['submitting'])) {
$image_name= $url ;
mysql_connect('********************) or die(mysql_error());
mysql_select_db('*************) or die(mysql_error());
mysql_query("DELETE $image_name FROM js_resume WHERE candidateID ='$candidateID'") or die(mysql_error());
$query = "UPDATE js_resume SET pic_stat = 'no' WHERE candidateID = '$candidateID'";
$result = mysql_query($query) or die(mysql_query());
mysql_close();
@unlink($tdir."/".$url);<-- I tried it this way and still gets the same error
echo'<span class="style2">Your photo has been deleted! Click <a href=" ag_upload_pic.php?candidateID=$candidateID" title="Please Reupload Photo!">HERE</a> to reupload photo!</span>';
}
?>
Sorry, Im still a novice.
Batoe
Re: Help, I can't Delete my image?????
Posted: Thu Feb 04, 2010 6:05 pm
by AbraCadaver
You still haven't given me the output of the echo, and you still haven't posted ALL the errors you get when you add the error reporting code.
Re: Help, I can't Delete my image?????
Posted: Fri Feb 05, 2010 4:02 pm
by cap2cap10
Thanks for the help, I found the glich!

$url was empty; variable was not being passed!
Thanks again, everyone
Batoe