Jump to content


Photo

unlink Command HELP!!!


  • Please log in to reply
7 replies to this topic

#1 digipit

digipit
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 25 June 2006 - 07:36 PM

Here's the code I've got for deleting a record in the MySQL database as well as the image associated with it on the server. The portion that deletes from the database is working perfectly, but I can't get it to delete the image off the server. This is a picture gallery I've created for a client. Getting it to delete the actual image is the last thing keeping me from finishing the project. All and any help is appreciated.

[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--]<?
$db_user_name = "*****";
$db_database_name = "****";
$db_password = "****";

$picture_id = $_GET['picture_id'];
$picture_name = $_GET['picture_name'];
$picture_url = $title . '.' . $_GET['picture_url'];

mysql_connect( 'localhost', $db_user_name, $db_password) or die('<br>Failed connect: ' . mysql_error());

mysql_select_db($db_database_name) or die('<br>Failed database: ' . mysql_error());

mysql_query("DELETE FROM pg_gallery WHERE picture_id = $picture_id") or die('<br>Failed query: ' . mysql_error());

mysql_close();

unlink('../../images/gallery/'.$picture_url);

echo 'File removed successfully.';
?>[!--colorc--][/span][!--/colorc--]

#2 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 25 June 2006 - 08:12 PM

The code syntax looks fine, but the relative path that you are using with unlink might be whats giving you trouble. Do you have delete privileges to "../../images/gallery/" directory?
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#3 digipit

digipit
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 25 June 2006 - 08:19 PM

I guess I do. I am the admin, but I've seen where others said to "chmod" it to 777. The folder itself is set to 777 but the individual images are not. I'm not sure how to go about doing this. I've also tried putting in a file directory path for the server but it still gives me fits. Any thoughts? Thanks.

#4 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 25 June 2006 - 08:21 PM

Should you be using "$picture_name" instead of "$picture_url"?
What is the contents of those vars?
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#5 digipit

digipit
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 25 June 2006 - 08:31 PM

picture_name is what the user adds in as a caption for the image. picture_url is the column in the db containing the actual name of the file (i.e. myimage.jpg). That's what I'm trying to delete and running into a world of trouble with it.

#6 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 25 June 2006 - 08:35 PM

I still am concerned about the relative path. Try something like this to check if you really have the correct filename:
$tempvar = '../../images/gallery/'.$picture_url);
if (file_exists($tempvar))
{
 echo $tempvar.' is a valid file';
}
else
{
 echo $tempvar.' does not exist';
}

Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#7 digipit

digipit
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 25 June 2006 - 08:43 PM

This is what I got: "../../images/gallery/ is a valid file". The weird thing is that it didn't show the file name though. Is there something wrong with the variable? Thanks for your help!

#8 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 25 June 2006 - 09:28 PM

$picture_url is an empty var, so you were trying to unlink a directory. What I would do is echo the contents of all of the vars related to the creation of the $picture_url variable, like $title and $_GET['picture_url']. You could insert this code at various places in your code to try to find which variable is not working.
echo  '<PRE>';
print_r($GLOBALS);
echo '</PRE>';

Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users