Jump to content


Photo

unset picture in folder via database to delete pic.


  • Please log in to reply
1 reply to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 23 May 2006 - 04:33 AM

I am trying to delete any picture in a folder that is not in the database via the unset statement

The idear is to plonk this in the folder with the members pictures to delete any picture not in the database.
Please help.




<?

//connect to the database

$db=mysql_connect("localhost");
mysql_select_db("members_pictures",$db);

// select the field name 

$query="SELECT * FROM picture ";
$result=mysql_query($query);

// if statement where picture = 1 to the users id

if(mysql_num_rows($result)==1){

}else{

// delete any other picture within that folder thats there.

unset($picture);
}

?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 May 2006 - 04:55 AM

unset deletes variables, are you sure you aren't looking for unlink?

If so, you could readdir() in a loop, and check the database for the filename.

        $dir = realpath("."); //current folder.
        if($dh=opendir($dir)) {
            while(($file=readdir($dh))!=false) {
                $result=mysql_query("SELECT `picture_file_name` FROM `picture` WHERE `picture_file_name` = '$file'");
                if(mysql_num_rows($result)<1) unlink($file); // no result DELETE FILE
            }
            closedir($dh);
        } else echo "directory error";

note, this is an example script and might not work just right for you. Oh, and this WILL delete files, so be careful. Test it someplace before you load it on your production site.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users