PHP + MYSQL file_exists

Discussion in 'PHP' started by cavendano, Jan 8, 2010.

  1. #1
    I have a directory with over 2,000 files...
    They are user generated so based on the users form input the file data is saved with a random filename and whatever values they entered for name and such. I have a script that cleans out any file older than 30 days but I started noticing that I had more files left on my database than I had physically on the server so I put in place another script that would run a mysql query and then check to see if the files actually were still on the server.
    What happens when I run the script is it executes within 2 seconds (which i find too quick) and it never is false!

    
    
    	$conn = mysql_connect("$host","$user","$pass");
    	if (!$conn) die ("Could not retrieve your information please try again later.");
    //Check if file exists on database but no actual file exists
    $result = mysql_query("SELECT * FROM table WHERE TO_DAYS(time)  <= TO_DAYS(NOW()) -1") or die("We are experiencing difficulties please try again later.");
    $i=0;
    while($row=mysql_fetch_array($result))
    	{
    $file = $row['finame'];	
    $filename = $root .'/temp/'. $file;
    echo $filename . '<br>';
    if ( file_exists($filename) ) {
    echo "Found $file in DB <br>";
    $i++;
    } else {
    mysql_query("DELETE FROM mob_userips WHERE finame ='$file'");
    echo "Deleted $file from DB <br>";
    
    }
    }
    echo $i;
    PHP:

     
    cavendano, Jan 8, 2010 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Does it echo out every filename? If it does then the query is fine
     
    JAY6390, Jan 8, 2010 IP
  3. cavendano

    cavendano Well-Known Member

    Messages:
    360
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #3
    It did echo every time...
    and you know something I figured out the problem...
    I was comparing my sql database count to the count that Filezilla (FTP) was giving me... I had 4000 files in the database and filezilla was only showing 1998 .... so you could see the reason for my concern....
    after you made your post I dug into it and found that it was Filezilla that has a bug... all the files were accounted for correctly!

    Thanks for your help!
     
    cavendano, Jan 8, 2010 IP