how to synchronize database table and directory with php

Posted by twmulloy on Stack Overflow See other posts from Stack Overflow or by twmulloy
Published on 2010-05-24T04:41:09Z Indexed on 2010/05/24 4:51 UTC
Read the original article Hit count: 234

Filed under:
|
|
|
|

hello, I have a directory with files and a database table with what should be the same files. I would like to be able to synchronize the database table with the directory. What would be the most efficient way to do this? or would I realistically only be able to do this in a brute manner?

Here's my approach:
1. retrieve all of the files in the directory as array
2. retrieve all of the filenames in the database table as array
3. loop through the file values in the directory array and use in_array() on the database table array to verify the filename is in that array, and if not then start building an array to insert the missing filenames. run db query to add each missing file row to database table
4. loop through directory array and use in_array() on the directory array and anything not found in the directory array will just be deleted from the table.

Is there a better way to go about this? or something better for this in php than in_array()?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql