3

I will be sending new files over from one computer to another computer. How do I make PHP auto detect new/updated files in the folders and enter the information inside the files into mysql database?

1
  • 1
    The question is not about version control, and it could contain binary information. We do not know how the information will be used within the DB. How is an VCS even an option here? @diEcho Commented Aug 26, 2011 at 9:07

4 Answers 4

6
  1. Get all files you already know from the database
  2. loop through the directory with http://www.php.net/manual/de/function.readdir.php
  3. if the file is known, do nothing
  4. if the file is not known, add it to the database
  5. In the end, delete all files no longer in the directory
Sign up to request clarification or add additional context in comments.

1 Comment

I'd use php.net/manual/en/class.directoryiterator.php to loop through the directory but yeah, basically that :)
2

I would pick a set-up where new files and old fields are in a separate directory.

But if you have no choice, you could check the modification date and match it with your last directory iteration. (Use filemtime for this).

Don't forget to do some database checking when you process an image though.

Comments

1

Save the timestamp of the last check and when you check next look at the fileinfo and check creation date. Even better yet because you store filecontens in a database, check for the time it was modified using: filemtime()

Comments

-5

You can't. PHP works as a preprocessor and even it has execution time limit (set in the configuration). If you need to process with PHP then make a PHP script that outputs a web page that use meta redirection to itself. Inside the script, you should loop over the files, query the database for the file name and its modification time, if it exists then nothing to do, otherwise, if the file name exists then it's an update, otherwise it's a new file.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.