当我上传到服务器时,php文件没有显示

时间:2015-08-22 05:26:32

标签: php

这是将excel文件上传到我的数据库的php,但是当我点击这个文件时将其上传到服务器时它没有显示任何东西。为什么它会发生。甚至没有导航但显示空页

 include 'Excel/reader.php';
        $retailername=$_SESSION['logged_name'];
        //require('SpreadsheetReader.php');
        set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
        include 'PHPExcel/IOFactory.php';


        if(isset($_POST['submit']))
        {
            $filename=$_FILES["csvFile"]["tmp_name"];


             if($_FILES["csvFile"]["size"] > 0)
             {

                $file = fopen($filename, "r");
                 while (($data = fgetcsv($file, 10000, ",")) !== FALSE)
                 {
                    $query = mysql_query("INSERT into chemicalbb(`CATEGORY`,`SUBCATEGORY`, `PRODUCT_DESCRIPTION`, `BRAND`, `PRODUCT_ID`, `QUANTITY`, `PRICE`,`vendor_name`,`PRODUCTNAME`,`EMPTY1`) 
                        values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$retailername','$data[7]','')");
                        mysql_query($query);

                 }
                fclose($file);


             }

            else if($_FILES['excelFile']['size']>0) 
            {

                $filename = basename($_FILES["excelFile"]["name"]);
                move_uploaded_file($_FILES["excelFile"]["tmp_name"], $filename);
                            try {
                                $objPHPExcel = PHPExcel_IOFactory::load($filename);
                                    } catch(Exception $e) {
                                        die('Error loading file "'.pathinfo($filename,PATHINFO_BASENAME).'": '.$e->getMessage());
                                    }
                        $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
                        $arrayCount = count($allDataInSheet); 
                for($i=2;$i<=$arrayCount;$i++)
                {
                    $CATEGORY=trim($allDataInSheet[$i]["A"]);
                    $SUBCATEGORY=trim($allDataInSheet[$i]["B"]);
                    $PRODUCT_DESCRIPTION=trim($allDataInSheet[$i]["C"]);
                    $BRAND=trim($allDataInSheet[$i]["D"]);
                    $PRODUCT_ID=trim($allDataInSheet[$i]["E"]);
                    $QUANTITY=trim($allDataInSheet[$i]["F"]);
                    $PRICE=trim($allDataInSheet[$i]["G"]);
                    $PRODUCTNAME=trim($allDataInSheet[$i]["H"]);
                    $query = mysql_query("INSERT into chemicalbb(`CATEGORY`,`SUBCATEGORY`, `PRODUCT_DESCRIPTION`, `BRAND`, `PRODUCT_ID`, `QUANTITY`, `PRICE`,`vendor_name`,`PRODUCTNAME`,`EMPTY1`) 
                        values('$CATEGORY','$SUBCATEGORY','$PRODUCT_DESCRIPTION','$BRAND','$PRODUCT_ID','$QUANTITY','$PRICE','$retailername','$PRODUCTNAME','')");
                        mysql_query($query);
                }


        }
        echo "<script type=\"text/javascript\">
                            alert(\" File has been successfully Imported.\");
                            window.location = \"landing.php\"
                        </script>";
        }
        if(isset($_POST['delete']))
        {
            mysql_query("DELETE FROM chemicalbb where vendor_name='$retailername'");
        }


    <div class="control-group">
                                <div class="control-label">
                                    <label>Select CSV File</label>
                                </div>
                                <div class="controls">
                                    <input type="file" name="csvFile" class="input-large">
                                </div>
                            </div>
                            or
                            <div class="control-group">
                                <div class="control-label">
                                    <label>Select Excel File</label>
                                </div>
                                <div class="controls">
                                    <input type="file" name="excelFile" class="input-large">
                                </div>
                            </div>
                            <div class="control-group">
                                <div class="controls">
                                <button type="submit" id="submit" name="submit" class="btn btn-primary button-loading" data-loading-text="Loading...">Upload</button>
                                </div>

1 个答案:

答案 0 :(得分:1)

有语法错误。您必须在最后一行

中关闭PHP标记,如下所示

之后关闭php标签
if(isset($_POST['delete']))
    {
        mysql_query("DELETE FROM chemicalbb where vendor_name='$retailername'");
    }
?>   //  Close Php Tag here