I have a code that needs to read in a file and has a parameter file. I need to know how to put in <=,<,=,>=,> operators that will be in my parameter file.
I beleive that it needs to go in this line:
$search=explode(':',strtoupper($params[0]));
but not sure if it will look like this
$search=explode('<','<=','>','>=','=',strtoupper($params[0]));
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
// check to see if file uploaded, using the super-global array $_FILES
if (isset($_FILES['UploadedFile']['tmp_name']))
{
# $_FILES['fieldname']['name'] gives the uploaded file name
print ("<p>");
$filename = dirname(__FILE__).'/'.$_FILES['UploadedFile']['name'];
move_uploaded_file($_FILES['UploadedFile']['tmp_name'], $filename);
$OUTFILE = fopen($filename, 'r') or die("Can't open $filename for read");
//read the entire file into an array
$params=file('parameters.txt');
//after this $type will have "SPORT"
$search=explode(':',strtoupper($params[0]));
$searchColumn=trim($search[0]);
$searchValue=trim($search[1]);
//after this $columns[0] will have "MODEL" && $columns[1] will have "PRICE"
$columns=explode("~",strtoupper(trim($params[1])));
//read the first line of the csv
$data = fgetcsv($OUTFILE,1000, "~");
//now find which column corresponds to "TYPE"
$typeIndex=array_search($searchColumn, $data);
//now find out the column index for each of the columns specified in parameters.txt
foreach($columns as $i=>$v)
{
if(FALSE===($columns[$i]=array_search($v, $data)) )
{
echo ("Column $v does not seem to exist");
unset($columns[$i]);
}
}
echo('<table>');
do{
//make sure that the type value of the current $data row matches what
//was provided in $type (in parameters.txt)
if( strtoupper($data[$typeIndex]) == strtoupper($searchValue) )
{
echo('<tr>');
//now iterate only over the set of requested columns
foreach($columns as $dataIndex){
echo("\t<td>{$data[$dataIndex]}</td>\r\n");
}
echo('</tr>');
}
}while (($data = fgetcsv($OUTFILE,1000, "~")) !== FALSE);
echo('</table>');
fclose($OUTFILE);
}
?>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<!-- <input type="hidden" name="MAX_FILE_SIZE" value=" " /> -->
<input name="UploadedFile" type="file" />
<input type="submit" value="UPLOAD" />
<h2> Soucre Code File</h2>
<p>
<?php
show_source(__FILE__);
?>
</p>
</body>
</html>
the file i will be reading in
MAKE~MODEL~TYPE~PRICE
Toyota~Camry~Sedan~18000
Toyota~Tacoma~Truck~19000
Ford~Mustang~Sport~21000
Chevrolet~Corvette~Sport~48000
Ford~F150~Truck~25000
Toyota~Highlander~SUV~35000
My Parameter file
Price<3500
MAKE~MODEL~PRICE