Log in

View Full Version : Check if new file exists!



M2com
03-19-2013, 04:49 AM
I would like to know how/where to start to get an a ajax or JavaScript script to check if a folder filled with text files was changed and then display them according to a php File. Let me know what I can do to clarify!


Thanks so much for your help!

-M2com

traq
03-19-2013, 06:16 AM
I would like to know how/where to start to get an a ajax or JavaScript script to check if a folder filled with text files was changed
changed since when?
where is the folder?


and then display them according to a php File.
I'm not at all sure what you mean by that.

Can you describe and/or give examples of what you want to happen?

M2com
03-19-2013, 11:17 PM
Thanks for the reply!

I mean if it was changed at any time, past year or the past couple seconds. The folder that is filled with text files Is located in the same directory that this script I'm asking about is.

The php script/file will format the information from the text files how I want it and give it the functionality I want, it's like a Facebook status feed.

traq
03-20-2013, 01:32 AM
JavaScript would not be able to do this. You'd need to use PHP (or another server-side language) - I'd suggest learning about the filemtime() (http://php.net/filemtime) function.

To expand on my "changed since when" question, checking if has changed "at any time" will not be very useful. If the file exists, that means it has been changed at least once. Same if it once existed but does not any longer. The only was a file will have not changed, ever, is if it never existed at all.

SO, you need a "since when" constraint. What timeframe are you checking against? I would suspect you want to check if there was any change "since last time I checked," meaning you'd also need to keep track of when you last checked.

It would make sense for your "checking" script to control your formatting script.

Now, JavaScript/AJAX can send an HTTP request to your PHP script, triggering this whole process. You'd need to decide how you want the information returned (JSON might be a good idea).