CSV错误消息未显示

时间:2015-01-19 13:17:36

标签: php csv

我可以上传和覆盖CSV文件中的数据。 但是当我上传错误的文件类型(示例上传PPT文件)时,错误消息“无效文件。请检查文件是否以.CSV格式上传!” 未显示。但好处是我的localhost数据库也没有更新(因为它不是正确的文件) 我应该如何编辑代码以便显示/提示错误?

 <?php
 session_start();
 if (isset($_POST["Upload"])) {
include "dbFunctions.php";
mysql_select_db($DB) or die(mysql_error());
$filename = $_FILES["file"]["tmp_name"];
if ($_FILES["file"]["size"] > 0) {
    $file = fopen($filename, "r");


    $count = 0;
    while (($excelData = fgetcsv($file, 10000, ",")) !== FALSE) {
        $count++;

        if ($count > 1) {
            $sql = "INSERT into abc (id, password, name, dob, contact_number, email, gender, module, school) values ('" . $excelData[0] . "',SHA1('" . $excelData[1] . "'),'" . $excelData[2] . "','" . $excelData[3] . "','" . $excelData[4] . "','" . $excelData[5] . "','" . $excelData[6] . "','" . $excelData[7] . "','" . $excelData[8] . "') ON DUPLICATE KEY UPDATE password=SHA1('" . $excelData[1] . "'), name='$excelData[2]', dob='$excelData[3]', contact_number='$excelData[4]', email='$excelData[5]', gender='$excelData[6]', module='$excelData[7]', school='$excelData[8]'";
            mysql_query($sql);

            $msg = 'CSV File has been successfully imported';
        } else {
            $msg = 'Invalid File. Please check that the file is uploaded in .CSV format!';
             }
         }
     }
 }
 ?>

 <!DOCTYPE html>
 <html>
     <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>**** System</title>
         <link href="stylesheet/style.css" rel="stylesheet"/>
     </head>
     <body>
     <?php
    include "navigationBar.php";
    ?>

    <h2>Load Details</h2>
    <?php
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    ?>
    <br>
    <?php
    echo $msg
    ?>

</body>

 </html>     

0 个答案:

没有答案