digipit Posted June 25, 2006 Share Posted June 25, 2006 [b]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.[/b][!--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--] Quote Link to comment https://forums.phpfreaks.com/topic/12878-unlink-command-help/ Share on other sites More sharing options...
dptr1988 Posted June 25, 2006 Share Posted June 25, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49440 Share on other sites More sharing options...
digipit Posted June 25, 2006 Author Share Posted June 25, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49443 Share on other sites More sharing options...
dptr1988 Posted June 25, 2006 Share Posted June 25, 2006 Should you be using "$picture_name" instead of "$picture_url"? What is the contents of those vars? Quote Link to comment https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49447 Share on other sites More sharing options...
digipit Posted June 25, 2006 Author Share Posted June 25, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49449 Share on other sites More sharing options...
dptr1988 Posted June 25, 2006 Share Posted June 25, 2006 I still am concerned about the relative path. Try something like this to check if you really have the correct filename:[code]$tempvar = '../../images/gallery/'.$picture_url);if (file_exists($tempvar)){ echo $tempvar.' is a valid file';}else{ echo $tempvar.' does not exist';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49450 Share on other sites More sharing options...
digipit Posted June 25, 2006 Author Share Posted June 25, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49451 Share on other sites More sharing options...
dptr1988 Posted June 25, 2006 Share Posted June 25, 2006 $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.[code]echo '<PRE>';print_r($GLOBALS);echo '</PRE>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49459 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.