How can I delete images stored in a database while deleting images in the corresponding folder?

Source: Internet
Author: User
New users ask for help. how to delete images stored in the database while deleting the images in the corresponding folder has just begun learning PHP, and I have made a source code on the internet. I have been wondering if I have any questions, how to delete the image files in the database and delete the corresponding images in the existing folder. after several days of research, how to use unlink has never been found. Please help us, thank you ~~~ For help, how can I delete images stored in the database while deleting images in the corresponding folder?
When I first started learning PHP, I got a source code on the Internet and studied it myself. I have been wondering how to delete image files in the database, I deleted the corresponding images in the existing folder. after studying how to use unlink for several days, I cannot find the essentials. thank you for your help ~~~~~

The images are stored in YDT and YXT in the ytp table. the corresponding folders are 2012/B and 2012/s in the root directory of the website, 2012/B/1337326878820.jpg and 2012/s/1337326878820.jpg are stored in the YDT and YXT fields.

Image storage code

Include ("config. inc. php ");
Include ("function. php ");
Include ("in. php ");
$ Conn = mysql_connect ($ YIHOST, $ YIUSER, $ YIPASS );
Mysql_query ("set names gbk ");
Mysql_select_db ($ YINAME );
If (! Isset ($ _ POST ['ylx']) or! Isset ($ _ POST ['ybh']) or empty ($ _ POST ['yfl '])
{
Mysql_close ();
Echo "script alert ('illegal submission! Please fill in the correct information and submit it again! '); History. back (); script ";
Exit;
}
$ YTP = yiup ($ _ FILES ["YTP"], 0, "no.jpg", array ('image/jpg ', 'image/jpeg', 'image/png ', 'image/pjpeg ', 'image/GIF', 'image/x-png'), 10485760, "tmp /");
If ($ YTP = "no.jpg ")
{
Mysql_close ();
Echo "script alert ('upload failed! Pay attention to the image format and file size! '); History. back (); script ";
Exit;
}
If ($ YTP! = "No.jpg ")
{
$ K = revert (100,999 );
$ YTP0 = time (). $ k. ". jpg ";
$ YTP1 = date ("Y"). "/s/". $ YTP0;
$ YTP2 = date ("Y"). "/B/". $ YTP0;
Yisw ("tmp/". $ YTP, $ YTP2, 800,600, 1 );
Yisw ($ YTP2, $ YTP1, 128,96, 0 );
Yisy ($ YTP2, "pub/water.gif ");
Unlink ("tmp/". $ YTP );
$ Exec = "insert into ytp (YZM, YYH, YLX, YBH, YFL, YXT, YDT) values ('". $ yimaoid. "','". $ YHID. "','". htmlencode2 ($ _ POST ['ylx']). "','". htmlencode2 ($ _ POST ['ybh']). "','". htmlencode2 ($ _ POST ['yfl ']). "','". $ YTP1 ."','". $ YTP2 ."')";
$ Result = mysql_query ($ exec );
}
Mysql_close ();
Echo "script" alert ('upload successful! '); History. back (); script ";
Exit;
?>



Image deletion code

Include ("config. inc. php ");
Include ("function. php ");
Include ("in. php ");
$ Conn = mysql_connect ($ YIHOST, $ YIUSER, $ YIPASS );
Mysql_query ("set names gbk ");
Mysql_select_db ($ YINAME );
If (empty ($ _ GET ['id'])
{
Mysql_close ();
Echo "script alert ('illegal submission! Please submit again! '); History. back (); script ";
Exit;
}
$ YID = htmlencode2 ($ _ GET ['id']);
$ Exec = "delete from ytp where YYH = $ YHID and YID = $ YID ";
Mysql_query ($ exec );
Mysql_close ();
Echo "script" alert ('deleted successfully! '); History. back (); script ";
Exit;
?>


------ Solution --------------------
Delete the images in the folder before deleting the data in the database.
$ SQL = "select YYH, YID from ytp where YYH = $ YHID and YID = $ YID ";
$ R = mysql_query ($ SQL );
$ Row = mysql_fetch_assoc ($ r );
Foreach ($ row as $ v) unlink ($ v );
$ Exec = "delete from ytp where YYH = $ YHID and YID = $ YID ";
...................................

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.