上传图片和表格

时间:2017-06-06 10:58:30

标签: php html sql forms

我一直在努力让这个文件/表单上传工作,但是当我上传表单时,会出现一个没有任何错误的空白页。

将图片文件名+路径上传到SQL,实际图片应该转到/ uploads地图。

任何错误检查的建议?

这是我的代码

<?php

if (isset($_POST['update']))
{
    $dbhost = 'localhost';
    $dbuser = 'heijsdb_user';
    $dbpass = 'maus';
    $conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect($dbhost, $dbuser, $dbpass));
    $controleur = $_SESSION["username"];
    $constatering = $_POST['constatering'];
    $radio = $_POST['radio'];
    $actie = $_POST['actie'];
    $date = $_POST['geplande_datum'];
    $verant = $_POST['verantwoordelijke'];
    $toelichting = $_POST['toelichting'];
    $filename = $_FILES['file']['name'];
    $filetype = $_FILES['file']['type'];
    if ($filetype == 'image/jpeg' or $filetype == 'image/png' or $filetype == 'image/jpg')
    {
        $move = move_uploaded_file($_FILES['file']['tmp_name'], './uploads/a' . $filename);
        $filepath = "./uploads/a" . $filename;
        if ($move)
        {
            echo "goed geupload";
        }
        else
        {
            echo "mis";
        }

        if (!$conn)
        {
            die('Could not connect: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        }

        $sql = "INSERT INTO logboek_afwijkingen (controleur, image, constatering, besmetting, actie, datum_gepland, verantwoordelijke, toelichting) 
            VALUES ('$controleur','$filepath', '$constatering', '$radio', '$actie', '$date', '$verant', '$toelichting')";
        mysqli_select_db($GLOBALS["___mysqli_ston"], 'heijsdb');
        $retval = mysqli_query($conn, $sql);
        if (!$retval)
        {
            die('Could not update data: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        }

        echo "Form send.";
        ((is_null($___mysqli_res = mysqli_close($conn))) ? false : $___mysqli_res);
    }
}
else
{
?>
               <form method = "post" action = "<?php
    $_PHP_SELF ?>" id="form1" enctype="multipart/form-data" class="w3-padding w3-main">
        <fieldset id="f1"><b>Logboek afwijkingen</b></fieldset>
            <table width= "600" border="1" cellspacing="1" cellpadding="1" class="w3-container w3-table">

                <tr><td width="200"><b>upload foto</b></td><td></td> <td width="100"><input type="file" size="3" name="file"></td></tr>


                <tr><td width="200"><b>constatering</b></td><td></td> <td width="100"><textarea style="margin: 0px; width: 252px; height: 94px;" name="constatering"></textarea></td></tr>

                <tr>
                    <td width="100"><b>kans op acute besmetting</b></td>
                    <td></td> 
                    <td><input type="radio"  value="ja" class="w3-radio" name="radio"> Ja<br />
                        <input type="radio"  value="nee" class="w3-radio" name="radio"> Nee<br /></td></tr>
                <tr>
                    <td width="100"><b>corrigerende actie</b></td>
                    <td></td> 
                    <td><textarea style="margin: 0px; width: 150px; height: 60px;" name="actie"></textarea></td>
                </tr>
                <tr>
                    <td width="100"><b>geplande datum</b></td>
                    <td></td> 
                    <td><input type="date" size="3" name="geplande_datum"></td>
                </tr> 

                <tr>
                    <td width="100"><b>verantwoordelijke</b></td>
                    <td></td> <td>
                    <input type="text" size="3" name="verantwoordelijke"></td>
                </tr>

                <tr>
                    <td width="100"><b>Toelichting</b></td>
                    <td></td> 
                    <td><textarea style="margin: 0px; width: 252px; height: 94px;" name="toelichting"></textarea></td>
                </tr>

            </table>  
                   <input type="submit" name="update" value="update" class="w3-bar w3-red" action="<?php
    echo $_SERVER['PHP_SELF']; ?>"> 
           </form>
<?php
}
?>

1 个答案:

答案 0 :(得分:0)

**[Mon Jun 12 09:33:27.652354 2017] [:error] [pid 21482] [client ***************] PHP Warning:  Unknown: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/var/www/) in Unknown on line 0, referer: http://kdlk.heijsgroep.nl/heijs/logboek.php**

我没有写入上传的权限