AdRock Posted December 5, 2006 Share Posted December 5, 2006 I have created a website which I don't want to have to manage so am trying to make it easy for someone to manage it.I have an admin area where the database can be managed but I have noticed that when images are no longer used (becuase the are relevant to news articles) it is taking up a lot of room in the images directory.Is it possible to have a form in the admin area for deleting images from the images directory so I don't have to go to my ftp access to delete unwanted images? Quote Link to comment Share on other sites More sharing options...
marcus Posted December 5, 2006 Share Posted December 5, 2006 You can use [url=http://us3.php.net/manual/en/function.ftp-delete.php]ftp_delete[/url] Quote Link to comment Share on other sites More sharing options...
jsladek Posted December 5, 2006 Share Posted December 5, 2006 unlink($filename);-John Quote Link to comment Share on other sites More sharing options...
papaface Posted December 5, 2006 Share Posted December 5, 2006 Use:[code]unlink("directoryincludingfileandextention");[/code]e.g. unlink("images/image.gif"); Quote Link to comment Share on other sites More sharing options...
marcus Posted December 5, 2006 Share Posted December 5, 2006 Yeah, unlink would be much easier. You can do something like[code]<?php$filename = $_POST[filename]; if(file_exists($filename)){ $unlink = unlink($filename); if($unlink){ echo "File deleted"; }else { echo "File not deleted"; } }else { echo "File does not exist"; };?>[/code] Quote Link to comment Share on other sites More sharing options...
AdRock Posted December 6, 2006 Author Share Posted December 6, 2006 Thanks, I'll give it a tryWhich one of these is right for adding a directory?[code] if(file_exists("/images/".$filename)) if(file_exists("/images/$filename"))[/code]In my database is records that can be deleted and in the database records are the names of images that are linked to that record. When I delete the record is it possible to delete the image at the same time using this method or do i have to connect to the database to pull the record out using mysql_fetch_array?It would be very handy to delete the image the same time as the record from the databaseHere is the code that I have which actualy deletes the record<h2>Delete a general article</h2>[code]<?php include_once("../includes/connection.php"); $id=$_GET['id']; $title=$_POST['title']; $content=$_POST['content']; $filename = $_POST[filename]; $query = "DELETE FROM articles WHERE id='$id'"; mysql_query($query); if(file_exists("/images/".$filename)){ $unlink = unlink("/images/".$filename); if($unlink){ echo "File deleted"; }else { echo "File not deleted"; } } mysql_close();?><p class="style3">Thankyou. News item successfully deleted.</p>[/code] Quote Link to comment 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.