<?php
function convert(){
//enable error reporting for debugging
error_reporting(E_ALL | E_STRICT);
//convert pdf's to html using payroll.sh script and
//pdftohtml command line tool
$program = "payroll.sh";
$toexec="sh /var/www/html/tmp/" . $program . " 2>&1";
$exec=shell_exec($toexec);
//display message from payroll.sh
//echo $exec;
//echo ('<br/>');
}
function process(){
$dir = '/var/www/html/tmp/converted';
//echo ('one');
if (is_dir($dir)) {
//echo ('two');
if ($dh = opendir($dir)) {
//echo ('three');
while (($file = readdir($dh)) !== false) {
//echo ('four');
if ($file != "." && $file != ".."){
echo 'opening file: ';
echo $file;
echo ("<br/>");
$fp = fopen('/var/www/html/tmp/converted/' . $file, 'r+');
$count = 0;
//while file is not at the EOF marker
while (!feof($fp))
{
$line = fgets($fp);
if($count==21)
{
$employeeID = substr($line,71,4);
echo 'employee ID: ';
echo $employeeID;
echo ('<br/>');
//echo ('six');
$count++;
}
else if($count==30)
{
$employeeDate = substr($line,71,10);
echo 'employee Date: ';
echo $employeeDate;
echo ('<br/>');
//echo ('seven');
$count++;
}
else
{
//echo ('eight');
//echo ('<br/>');
$count++;
}
}
fclose($fp);
closedir($dh);
}
}
}
}
}
convert();
process();
?>
I am setting up a php script that will take a paystub in pdf format, convert it to html, then import it into Drupal after getting the date and employee ID.
The code only seems to process the first file in the directory then it gives me this:
opening file: dd00000112_28_2010142011-1.html
employee ID: 9871
employee Date: 12/31/2010
Warning: readdir(): 3 is not a valid Directory resource in /var/www/html/pay.mistequaygroup.com/payroll.php on line 29
The '3' in the error really confuses me, and google is not helping much. Could it be the 3rd iteration of the loop? The only files in the directory reddir() is scanning are the .html files waiting to be processed. Any ideas?
Also, how does my code look? I'm fairly new to doing any real programming and I don't get too much input around work.