dongle19863 2016-07-07 18:28
浏览 41

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

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(). "
";

 }
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用