Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-03-2012, 07:22 AM   PM User | #1
ycpc55
New Coder

 
Join Date: Jan 2007
Posts: 42
Thanks: 4
Thanked 0 Times in 0 Posts
ycpc55 is an unknown quantity at this point
delete image from folder

Hi
i was wondering if anyone can help me with a small problem im having? i have this script that will let users delete there messages from my database witch is working great and with each message they save they have to upload a image it will save the path of the image in the database and save the image to a folder is there anyway when they delete a message it will also delete the image in the folder by grabbing the path from the selected message there trying to delete? i have tried using unlink($image); but have no idea how to go about adding this thanks...
my code:
PHP Code:
<?php
$checkbox 
$_POST['checkbox'];
$delete    mysql_real_escape_string(strip_tags($_POST['delete']));
$user       mysql_real_escape_string($_SESSION['id']);
if(
$delete){
for(
$i=0;$i<$count;$i++){
$del_id $checkbox[$i];
$sql "UPDATE messages SET
WHERE id = '{$del_id}'
And username = '{$user}'"
;
mysql_query($sql$conn
or die(
'Error in query:<br>'$sql .'<br>'.mysql_error($conn).'<br>Time of Error: '.date("l F j, Y, G:i:s T"));
}
if(
$result){
echo 
"<meta http-equiv=\"refresh\" content=\"0\">\n";
}
}
mysql_close();
?>
ycpc55 is offline   Reply With Quote
Old 07-03-2012, 08:53 AM   PM User | #2
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by ycpc55 View Post
Hi
i was wondering if anyone can help me with a small problem im having? i have this script that will let users delete there messages from my database witch is working great and with each message they save they have to upload a image it will save the path of the image in the database and save the image to a folder is there anyway when they delete a message it will also delete the image in the folder by grabbing the path from the selected message there trying to delete? i have tried using unlink($image); but have no idea how to go about adding this thanks...
my code:
PHP Code:
<?php
$checkbox 
$_POST['checkbox'];
$delete    mysql_real_escape_string(strip_tags($_POST['delete']));
$user       mysql_real_escape_string($_SESSION['id']);
if(
$delete){
for(
$i=0;$i<$count;$i++){
$del_id $checkbox[$i];
$sql "UPDATE messages SET
WHERE id = '{$del_id}'
And username = '{$user}'"
;
mysql_query($sql$conn
or die(
'Error in query:<br>'$sql .'<br>'.mysql_error($conn).'<br>Time of Error: '.date("l F j, Y, G:i:s T"));
}
if(
$result){
echo 
"<meta http-equiv=\"refresh\" content=\"0\">\n";
}
}
mysql_close();
?>
You need to get the image location from the database before deleting the database query and then it's just unlinking the image. Then you need to delete from database.

So the order it needs is

Fetch image path
Delete database
Delete file

You can get the database queries by researching google if your not 100% sure
devinmaking is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:18 AM.


Advertisement
Log in to turn off these ads.