The script I have been working on makes a directory, copies two directories and two files into the directory it made, and then edits the two files copied, replacing certain strings with values that I assign through two variables in the script. I have the script tested and working. Here's where I get stumped...
I am setting up a cron job to run the script, but, I only want it to run if a specific file exists. I thought this would be easy as I would just have to do something like if(file_exists("blah.txt")){ Run Script }. This is the thing though, the file that the script checks for is created dynamically by a form submission, the form is named based on the value of a text box that the form posts.
Example; *-newfile.txt (the * being the value of the text box the form posted)
Every time the cron script finds a file with that naming convention I want it to loop through the script for each file it finds.
So basically, here's how it works so far:
1: user submits form with a text box filled in (example value : blah)
2: form posts to small script which creates local file called "blah-newfile.txt"
3: 3 cron checks if file exists (if I put the file name in manually like this if(file_exists("blah-newfile.txt")){ Run Script } it runs
4: cron uses - include('blah-newfile.txt'); (which contains the word they put into the form value) to insert the files contents into the value of a variable used in the cron. (example contents : "blah" - including quotes)
So basically the cron script has a first line that looks like $variable = include("blah-newfile.txt");
The problem I am having is writing something like: if(file_exists("*-newfile.txt")){ Run Script }
I have tried using glob as it feels as though this is the only solution for using a wildcard in a file_exists, but it doesnt seems to work and when I try and echo the variable it just says "Array to string conversion" as an error. So I try to do print readable on my array and it says that the value passed is not an array.
Here is a copy of the part of the script that checks if the file exists, I apologize for writing so much but wanted to make my problem perfectly clear:
$dir = "path/to/my/file/";
$newfile = glob($dir.'*-newfile.txt');
if(file_exists($newfile)){
foreach($newfile as $newfilerun) {
$variable = include($newfilerun);
RUN SCRIPT
}
Is there anything that anyone can see that I am doing wrong? If it is an easy solution, I apologize in advance for my stupidity
PLEASE, PLEASE someone help. If you see that I am wrong and respond, please paste an example or edit mine so that it will work or make recommendations on other ways of achieving this. Any help is GREATLY appreciated.