I made a little picture gallery for my website. The images and thumbnails are stored on the server and the information in a database. I know how to delete the information from the databasem, but how would I include instructions in the php script to also remove the thumb and image from the server? - <?php
-
if($_GET["cmd"]=="delete")
-
{
-
$sql = "DELETE FROM $table WHERE id=$id";
-
-
// code to delete images from server
-
-
$result = mysql_query($sql);
-
-
echo "<br><br><p align='center'><span style='color:red'><b>The Image and Information has been Deleted!<br><br>";
-
}
-
?>
6 23379
Before deleting the RECORD. Delete the files
try the unlink() delete() functions ...
i hope you have the file locations stored on the database
fetch it delete the files
delete the record.
No, I don't have the location of the image files stored in the database? Is this a good idea? If so, how would I show or store the path to images? I'd have a field named img_url and have the location like this: (/home/pictures/image_uploads/)
To unlink a file I would use this: [PHP]unlink("$img_url/tree.jpg");[/PHP]
How would I tie this in with a delete script that removes the information regarding this image from the database?
No, I don't have the location of the image files stored in the database? Is this a good idea? If so, how would I show or store the path to images? I'd have a field named img_url and have the location like this: (/home/pictures/image_uploads/)
To unlink a file I would use this: [PHP]unlink("$img_url/tree.jpg");[/PHP]
How would I tie this in with a delete script that removes the information regarding this image from the database?
ei david,
it doesn't matter if you dont have you directory paths.. as long as you know where your images are located... and most importanty the image filename should be save in the database..
ok... how you would tie it together with delete script.. heres how.. - $img_dir = 'image_directory_name/';
-
$img_thmb = 'thumbnail_directory_name/';// if you had thumbnails
-
-
$image_name = $row['image_name'];//assume that this is the image_name field from your database
-
-
//unlink function return bool so you can use it as conditon
-
if(unlink($img_dir.$image_name) && unlink($img_thmb.$image_name)){
-
//assume that variable $image_id is queried from the database where your image record your about to delete is...
-
$sql = "DELETE FROM table WHERE image_id = '".$image_id."'";
-
$qry = mysql_query($sql);
-
}else{
-
echo 'ERROR: unable to delete image file!';
-
}
ok? have fun... ^___^
bonski
Thank you for the example. - $sql = "DELETE FROM table WHERE image_id = '".$image_id."'";
May I ask why you placed the image_id like this '".$image_id."'instead of like this '$image_name'?
Thank you for the example. - $sql = "DELETE FROM table WHERE image_id = '".$image_id."'";
May I ask why you placed the image_id like this'".$image_id."'instead of like this '$image_name'?
oh... well i'm just used to do it like that... its a concatenation... notice the dot(.)
well, i guess... they are just the same.. im just doing it like that so that its easy for me to trace... ^___^
ok... your welcome...!
Here's the code that I'm trying to use from this post.. - <?php include('dbconnect.php');
-
-
$img_dir = '../images/ads/';
-
$img_thmb = '../images/ads/sml_';
-
-
$ad_photo = $row['ad_photo'];
-
-
//unlink function return bool so you can use it as conditon
-
if(@unlink($img_dir.$ad_photo) && @unlink($img_thmb.$ad_photo)){
-
$sql = "DELETE FROM pbsl_ads WHERE ad_id = '".$ad_id."'";
-
$qry = mysql_query($sql);
-
}else{
-
echo 'ERROR: unable to delete image file!, <a href=index.php> back</a>';
-
}
-
-
?>
The image wont delete from the server. I'm able to delete info from database.
This is what I have in my db table: - `ad_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-
`ad_date` VARCHAR(60) NOT NULL,
-
`ad_order` INT(3) NOT NULL,
-
`ad_name` TEXT NOT NULL, // this is the name of the person
-
`ad_info` TEXT NOT NULL,
-
`ad_email` TEXT NOT NULL,
-
`ad_photo` VARCHAR(50) NOT NULL, // this is the photo
-
`ad_cardphoto` VARCHAR(50) NOT NULL // this is the business card photo
Thanks for any help
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Silvia |
last post by:
Hi,
I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image
the listview, when do that and capture another image, the image...
|
by: php newbie |
last post by:
I am getting error messages when I try to delete from a table using
the values in the table itself. The intent is to delete all rows from
TableA where col_2 matches any of the col_1 values.
...
|
by: Matt Hamilton |
last post by:
I have a simple image gallery where I want to allow users to delete files.
The problem I have is that after an image is displayed in the browser, I am
not able to delete the file because "The...
|
by: Silvia |
last post by:
Hi,
I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image
the listview, when do that and capture another image, the image...
|
by: Ed |
last post by:
All of a sudden my previously working code started throwing this error. from
the SqlDatasource. I am using C# and Asp.net 2.0.
Getting the following error:
You have specified that your delete...
|
by: Wannabe |
last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything
working except the delete command. The page reloads except the row I am
trying to delete is still there. I believe it is...
|
by: Wannabe |
last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything
working except the delete command. The page reloads except the row I am
trying to delete is still there. I believe it is...
|
by: deppeler |
last post by:
I have a script that allows the user to upload images to the server & writes the file name to a flat file DB.
I have another script that allows the user to delete the image entry from the DB.
Is...
|
by: gerardianlewis |
last post by:
Any help appreciated.
(VB.NET under XP and Vista, SP1 installed)
My code, inherited from a VB6 version of an app that ran under W98,
loads an image from a file into a PictureBox. The user may...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |