Jump to content

Recommended Posts

[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--]
Link to comment
https://forums.phpfreaks.com/topic/12878-unlink-command-help/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49443
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49450
Share on other sites

$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]
Link to comment
https://forums.phpfreaks.com/topic/12878-unlink-command-help/#findComment-49459
Share on other sites

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.