dongxixiu9134 2017-04-18 16:41
浏览 22

图像不存储在文件夹中只有名称存储在数据库中

I have a table which have an image input file. When i add another row by using "Add Row" button. which mean another row have an image input file as well. Which mean every row have an image input file if a new row is added. So my problem here is when i submit the table form, the image file name.withExtension was saved into database, but when i check to the folder that i set to store the image, there was no images found in the folder. I only can see the image name for every row was added into database. Below is my code

<?php 
error_reporting(-1);


if(isset($_POST['travel'])){

        $merchant   = $_POST["merchant"];
        $remark = $_POST["remark"];

    for ($i = 0; $i < count($_POST["merchant"]); $i++){
        $merchant   = $_POST["merchant"][$i];
        $remark = $_POST["remark"][$i];

        $file = rand(1000,100000)."-".$_FILES['bill_image']['name'][$i];
        $file_loc = $_FILES['bill_image']['tmp_name'][$i];
        $file_basename = substr($file, 0, strripos($file, '.'));
        move_uploaded_file($file_loc,"../uploads/exp/".$file);

        $save_new_record = "INSERT INTO `report`(`merchant`, `remark`, `bill_image`, `bill_image_type`) VALUES (?, ?, ?, ?)";

        $stmt5 = $mysqli->prepare($save_new_record);

        $stmt5->bind_param('ssiisssssbsss', $merchant, $remark, $file, $file);


        if ($stmt5->execute() == false){
                echo 'query failed: ' . $mysqli->error;
                }
                $stmt5->close();
        }
        echo"<meta http-equiv=\"refresh\"content=\"0;URL=index.php\">";
}
//Include Global page
    include ('includes/global.php');
?>
<SCRIPT language="javascript">
        function addRow(tableID) {

            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);

            var colCount = table.rows[0].cells.length;

            for(var i=0; i<colCount; i++) {

                var newcell = row.insertCell(i);

                newcell.innerHTML = table.rows[0].cells[i].innerHTML;
                //alert(newcell.childNodes);
                switch(newcell.childNodes[0].type) {
                    case "text":
                            newcell.childNodes[0].value = "";
                            break;
                    case "text":
                            newcell.childNodes[0].value = "";
                            break;
                    case "text":
                            newcell.childNodes[0].value = "";
                            break;
                    case "file":
                            newcell.childNodes[0].value = "";
                            break;
                }
            }
        }

        function deleteRow(tableID) {
            try {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;

            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                var chkbox = row.cells[0].childNodes[0];
                if(null != chkbox && true == chkbox.checked) {
                    if(rowCount <= 1) {
                        alert("Cannot delete all the rows.");
                        break;
                    }
                    table.deleteRow(i);
                    rowCount--;
                    i--;
                }


            }
            }catch(e) {
                alert(e);
            }
        }
</SCRIPT>
<div class="wrapper">
    <div class="row">
        <div class="col-mg-8">

            <ul class="nav nav-tabs tabs">
            <li class="active tab">
                <a href="#travel" data-toggle="tab" aria-expanded="false">
                    <span class="visible-xs"><i class="fa fa-home"></i></span>
                    <span class="hidden-xs">Travel</span>
                </a>
            </li>
            </ul>

    <div class="tab-content">
        <div class="tab-pane active in" id="travel">
            <div class="panel panel-info">
                <div class="panel-body">
                <form action="" method="post" role="form" id="dist" enctype="multipart/form-data">

                    <table class="table table-hover" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                            <th><input name="checkAll" id="checkAll" type="checkbox" /></th>
                            <th class="text-left"><?php echo $Merchant; ?></th>
                            <th class="text-left"><?php echo $Remark; ?></th>
                            <th class="text-left"><?php echo $Image; ?></th>
                            </tr>
                            </thead>
                        <tbody id="dataTable">
                            <tr>
                                <td><input type="checkbox" name="chk[]" class="checkbox1"></td>
                                <td><input class="form-control" placeholder="<?php echo $Merchant ;?>" id="merchant" name="merchant[]" type="text" /></td>
                                <td><input class="form-control" placeholder="<?php echo $Remark ;?>" id="remark" name="remark[]" type="text" /></td>
                                <td><input type="file" name="bill_image[]" /></td>
                            </tr>
                        </tbody>
                    </table>

                    <input type="button" class="btn-sm btn-primary" value="Add Row" onclick="addRow('dataTable')" />

                    <input type="button" class="btn-sm btn-danger" value="Delete Row" onclick="deleteRow('dataTable')" />

                    <div class="panel-footer">
                        <button type="submit" name="travel" class="btn btn-primary btn-block"><span class="glyphicon glyphicon-log-in"></span>  Save</button>
                    </div>
                </form>

                </div>
            </div>
        </div>
    </div>
        </div>
    </div>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
    • ¥15 不小心不正规的开发公司导致不给我们y码,
    • ¥15 我的代码无法在vc++中运行呀,错误很多
    • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
    • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
    • ¥30 ppOCRLabel导出识别结果失败
    • ¥15 Centos7 / PETGEM
    • ¥15 csmar数据进行spss描述性统计分析
    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了