Help, I can't Delete my image?????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Help, I can't Delete my image?????

Post 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?? :banghead:

Thanks in advance,

Batoe
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help, I can't Delete my image?????

Post 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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Help, I can't Delete my image?????

Post by cap2cap10 »

ok, this was the error:

Warning: unlink(uploads/thumbs/) [function.unlink]: Is a directory in

any ideas?

Thanks in advance,

Batoe
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help, I can't Delete my image?????

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Help, I can't Delete my image?????

Post 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 :banghead:

Batoe
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help, I can't Delete my image?????

Post 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.

Code: Select all

echo $tdir . $url;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Help, I can't Delete my image?????

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help, I can't Delete my image?????

Post 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.

Code: Select all

echo $tdir . $url;
What did this output?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Help, I can't Delete my image?????

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help, I can't Delete my image?????

Post 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');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Help, I can't Delete my image?????

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help, I can't Delete my image?????

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Help, I can't Delete my image?????

Post by cap2cap10 »

Thanks for the help, I found the glich! :lol: $url was empty; variable was not being passed!

Thanks again, everyone

Batoe
Post Reply