PHP文件未在centOS服务器上创建

时间:2016-07-07 18:28:52

标签: php

我有一个我创建的表单。我在本地机器上测试了这个代码,但是当我设置一个centOS服务器,并将代码放在服务器上时,我无法获得在目录中创建文件的代码。该文件夹具有对所有用户的读取,写入和执行权限,但无论出于何种原因,当我提交表单时,根本不会创建csv文件。我不怀疑在本地测试代码时与服务器上的代码有什么不同。除非我的文件路径代码不正确,但我觉得它是正确的。也许因为我已经看了这么长时间,有一些我没有发现的东西。

这是我创建的html表单。

<!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>

这是我正在使用的PHP代码。

<?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. "\r\n"; 
    }
    else
    {
        $result .= implode(",",$header). "\r\n".
                        $dates. " ,". $driver. ", ". $custnum. " ,". $invnum. ", ". $proddesc. ", ". $sz. ", ". $case. " ,". $bottle. ", ". $chkit. "\r\n";
    }

    /*foreach ($fp as $file)
    {
        if(substr($file,0,8) != 'header 1')
        {
            $result .= implode(",",$header). "\r\n".
                        $driver. " ". $dates. " ". $custnum. " ". $invnum. " ". $proddesc. " ". $sz. " ". $case. " ". $bottle. " ". $chkit. "\r\n";
        }
        else
        {
            $result .= 
                    $driver. " ". $dates. " ". $custnum. " ". $invnum. " ". $proddesc. " ". $sz. " ". $case. " ". $bottle. " ". $chkit. "\r\n";
        }

    }*/

    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 "\r\n" .getcwd(). "\r\n";

 }
?>

0 个答案:

没有答案