I have a script that examines a directory and makes sure that the files have not been modified for 30 seconds (to make sure the files have stopped transferring) and then takes those files and feeds them to ps2pdf to generate pdf's out of them.
The problem is that if the files have spaces in the name the script pukes. Any ideas?
Is there a cleaner way to do this?
#!/usr/bin/php
<?php
$inputDirectory = "/home/distillery/dropoff";
$outputDirectory = "/home/distillery/pickup";
$ps2pdf = "/usr/bin/ps2pdf";
#read file(s) into an array
if ($files = opendir($inputDirectory)){
/*
* Loop through the array making pdf's
* as long they aren't "." and ".." of course
*/
while (false !== ($currentFile = readdir($files))){
if ($currentFile != "." && $currentFile != "..") {
#get current time (unix epoch)
$currentTime = date(U);
#get file times (remember, it's epoch)
$fileTime = date(filemtime("$inputDirectory/$currentFile
"));
$remainder = $currentTime - $fileTime;
#IF file is older than 30 seconds
#make it a pdf and print it
if ($remainder > 30){
$currentPDF = $currentFile . ".pdf";
$makePDF = `$ps2pdf $inputDirectory/$currentFile
$outputDirectory/$currentPDF`;
sleep(4);
$cleanup = unlink("$inputDirectory/$currentFile"
);
}//end if
}//end if
}//end while
}else{
echo "Nothing to do!";
}
?>