【问题标题】:after import csv file, redirects to http://localhost/index.php导入 csv 文件后,重定向到 http://localhost/index.php
【发布时间】:2015-03-26 18:05:44
【问题描述】:

好的,我已经创建了一个页面来导入我的股票文件,该文件位于 .csv 文件中(可以正常工作),但导入完成后,页面直接转到我的 localhost/index.php 而不是返回“ok”消息...这是为什么呢?

代码如下:

<form enctype="multipart/form-data" method="post" role="form">
<div class="form-group">
    <label for="exampleInputFile">Importar archivo</label>
    <input type="file" name="file" id="file" size="150">
    <p class="help-block">Solo archivos .csv</p>
</div>
<button type="submit" class="btn btn-default" name="Import"         value="Import">Importar</button>
</form>
<input type="button" onclick=" location.href='http://localhost/inicio.html'     " value="Inicio" name="boton" /> 
<?php 
if(isset($_POST["Import"]))
{
//me conecto a la BD
$conexion=mysql_connect("localhost","root","") or die("Problemas en la conexion");
mysql_select_db("kontor",$conexion) or die("Problemas en la seleccion de la base de datos");

echo $filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
    $file = fopen($filename, "r");
    $count = 0; 
    while (($emapData = fgetcsv($file, 10000, ";", '"')) !== FALSE)
    {
        $count++; 
        if($count>1){  
        mysql_query("INSERT into stock (SKU,nombre,descr,prbruto,prneto,fechaing,cantcentral,cantarauco,cantdrug,canttrebol) values ('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$emapData[5]','$emapData[6]','$emapData[7]','$emapData[8]','$emapData[9]')", $conexion) or die("Problemas en el select: ".mysql_error());

        }       
    }
    fclose($file);
    echo 'Archivo importado';
    header('Location: index.php');
}
else
    echo 'Formato de archivo incorrecto';
}
?>

【问题讨论】:

  • 您正在使用:header('Location: index.php');

标签: php mysql apache csv import


【解决方案1】:

从您的代码中删除 header('Location: index.php');

这是导致重定向的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 2015-01-11
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    相关资源
    最近更新 更多