I have a form that i have created. i tested this code on a local machine, but when i setup a centOS server, and place the code on the server, i cannot get the code to create a file in the directory. The folder has read, write, and execute permissions for all users, but for whatever reason, when i submit the form, the csv file does not get created at all. I do not suspect that anything different would be put in play when testing the code locally compared to on the server. Unless my file path is code incorrectly, but i feel that it is correct. Maybe since i have been looking at this for so long, there is something that I am not spotting.
This is the html form that i have created.
<!DOCTYPE HTML>
<html>
<head>
<title> Drive Check In </title>
<script type = "text/javascript" src = "jquery-2.2.1.js"> </script>
<script type="text/javascript" src="http://digitalbush.com/wp-content/uploads/2013/01/jquery.maskedinput-1.3.1.min_.js"></script>
<script type = "text/javascript">
function getDate()
{
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if (dd < 10)
{
dd = '0' + dd;
}
if (mm < 10)
{
mm = '0' + mm;
}
today = mm + '/' + dd + '/' + yyyy;
document.getElementById('dates').value = today;
document.getElementById('dates2').value = today;
document.getElementById('dates3').value = today;
document.getElementById('dates4').value = today;
document.getElementById('dates5').value = today;
document.getElementById('dates6').value = today;
}
$('form').submit(function () {
// Get the Login Name value and trim it
var name = $.trim($('#drivers').val());
// Check if empty of not
if (name === '') {
alert('Text-field is empty.');
return false;
}
});
</script>
<body onload = "getDate()">
<form action = "drivers.php" target = "drivers.php" method = "post" name = "shortage" id = "shortage">
<table id = "main">
<tr>
<td><table id = "shortages">
<h1> Shortages </h1>
<thead>
<tr>
<th> Date </th>
<th> Driver </th>
<th> Customer# </th>
<th> Invoice# </th>
<th> Product Description </th>
<th> Size </th>
<th> CS </th>
<th> Btls </th>
<th> CHK Itls </th>
</tr>
</thead>
<tr>
<td> <input type = "text" id = "dates" size = "6" name = "dates" readonly = readonly onblur = "checkDate()"> </input></td>
<td>
<select id = "drivers" name = 'drivers' >
<option value = ""> </option>
<option value = "name1"> Name 1 </option>
<option value = "name2"> Name 2 </option>
</select></td>
<td> <input type = "number" min = "1" max = "99999999" id = "customernum" name = "customernum" > </input> </td>
<td> <input type = "number" min = "1" max = "99999999" id = "invoicenum" name = "invoicenum" > </input> </td>
<td> <input type = "text" id = "proddes" name = "proddes" > </input> </td>
<td> <input type = "number" min = "0" max = "999999" id = "size" name = "size" > </input> </td>
<td> <input type = "number" min = "0" max = "999999" id = "cs" name = "cs" > </input> </td>
<td> <input type = "number" min = "0" max = "999999" id = "btls" name = "btls" > </input> </td>
<td> <input type = "text" id = "chkitls" name = "chkitls" size = "5"> </input> </td>
</tr>
</table>
<tr>
<td><input type = "submit" value = "submit" name = "mydrivers" > </td>
</tr>
</tr></table>
</form>
</html>
This is the php code that i am working with.
<?php
if(isset($_POST['mydrivers']))
{
$month = date('M');
$fp = file('Report/Shortage/'.$month. '/Shortage'.date('m-d-y'). ".csv");
//$fi = fopen('driver'.date('m-d-y'). ".csv", "a");
$header=array("Date", "Driver", "Customer #", "Invoice #", "Product Description", "Size", "CS", "Btls", "CHK Itls");
$driver = $_POST['drivers'];
$dates = $_POST['dates'];
$custnum = $_POST['customernum'];
$invnum = $_POST['invoicenum'];
$proddesc = $_POST['proddes'];
$sz = $_POST['size'];
$case = $_POST['cs'];
$bottle = $_POST['btls'];
$chkit = $_POST['chkitls'];
$result = '';
$search = "Driver";
$line_number = false;
while(list($key, $line) = each($fp) and !$line_number)
{
$line_number = (strpos($line, $search) !== FALSE);
}
if($line_number)
{
$result .=
$dates. " ,". $driver. " ,". $custnum. ", ". $invnum. ", ". $proddesc. ", ". $sz. " ,". $case. ", ". $bottle. ", ". $chkit. "
";
}
else
{
$result .= implode(",",$header). "
".
$dates. " ,". $driver. ", ". $custnum. " ,". $invnum. ", ". $proddesc. ", ". $sz. ", ". $case. " ,". $bottle. ", ". $chkit. "
";
}
/*foreach ($fp as $file)
{
if(substr($file,0,8) != 'header 1')
{
$result .= implode(",",$header). "
".
$driver. " ". $dates. " ". $custnum. " ". $invnum. " ". $proddesc. " ". $sz. " ". $case. " ". $bottle. " ". $chkit. "
";
}
else
{
$result .=
$driver. " ". $dates. " ". $custnum. " ". $invnum. " ". $proddesc. " ". $sz. " ". $case. " ". $bottle. " ". $chkit. "
";
}
}*/
if(!is_dir('Report/Shortage/'.$month))
{
mkdir('Report/Shortage/'.$month);
}
file_put_contents('Report/Shortage/'.$month. '/Shortage'.date('m-d-y').".csv", $result);
//myfputcsv($fp, $result);
echo "data added ";
//echo "
" .getcwd(). "
";
}
?>