<?php
//this variable tells us how many drupal nodes or 'paystub pages' we need to create
$nodeCount = 0;
$i = 0;
//needed for creating a drupal node
//for this code to work this script must be run from the root of the drupal installation
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if ($handle = opendir('/var/www/html/pay.miste.com/upload'))
{
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$nodeCount++;
//We convert the pdf documents into text documents and move put them in the converted folder
$command = "pdftotext /var/www/html/pay.mis.com/upload/" . $file . " /var/www/html/pay.mis.com/upload/converted/" . $file . ".txt";
//Execute the command above
$output = exec($command);
}
}
closedir($handle);
}
//subtract two because the folders "array" and "converted" are included because PHP does not differentiate
//between folders and files
$nodeCount = $nodeCount - 2;
echo "<br />";
echo "I counted $nodeCount pdf files";
echo "<br />";
//open the directory
if ($handle2 = opendir('/var/www/html/pay.mis.com/upload/converted'))
{
//check to see if we have reached the last file of our directory, if not stay in loop
while (false !== ($currentText = readdir($handle2)))
{
//filter out files named . and ..
if ($currentText != "." && $currentText != "..")
{
//Create a file for array to be printed to
$createArray = fopen("/var/www/html/pay.mist.com/upload/arrays/" . $currentText . ".txt", "w+") or die ("Cannot find file to create array, ID 2");
//read the file we are on from the loop into the array
$currentArray = file("/var/www/html/pay.mist.com/upload/converted/" . $currentText, FILE_SKIP_EMPTY_LINES) or die ("Cannot find file to create array, ID 1");
//search array and print to screen
$x = array_search("EMPLOYEE NO.", $currentArray);
echo "Employee # index: $x";
echo "<br />";
//print array to .txt file for debugging purposes
$out = print_r($currentArray, true);
fwrite($createArray, $out);
fclose($createArray);
}
}
}
?>
I'm not sure why, google is no help. array_search is not returning a value even though I know its in the array. Any ideas?
Edit:here is a link to my last thread for some more info on the subject.
This post has been edited by JordanH: 22 October 2010 - 10:42 AM

New Topic/Question
Reply




MultiQuote






|