简体   繁体   English

导入csv文件后,重定向到http://localhost/index.php

[英]after import csv file, redirects to http://localhost/index.php

Ok, I've made a page to import my stock file, which is in a .csv file (which works fine), but after the import is made, the page goes directly to my localhost/index.php instead of returning the "ok" message... why is that? 好的,我已经制作了一个页面来导入我的股票文件,该文件位于.csv文件中(可以正常工作),但是导入完成后,该页面直接进入我的localhost/index.php而不是返回“好”消息...那是为什么?

here's the code: 这是代码:

<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';
}
?>

Remove header('Location: index.php'); 删除header('Location: index.php'); from your code. 从您的代码。

That is causing the redirection. 这导致了重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从CodeIgniter网址中删除index.php重定向到本地主机 - Removing index.php from CodeIgniter url redirects to localhost file_get_contents(&#39;http://localhost/api/index.php?get = x&#39;); 如何使其工作? - file_get_contents('http://localhost/api/index.php?get=x'); how to make it work? 刷新页面2次后,header(&#39;location:index.php&#39;)将我重定向到index.php - header('location:index.php') redirects me to index.php after refreshing the page for 2 times 在子文件夹重定向中使用index.php以及htaccess文件中有多少 - using index.php in subfolder redirects and how many in htaccess file http://localhost/myphpadmin/index.php仅显示代码 - http://localhost/myphpadmin/index.php only shows code index.php工作正常,但是http:// localhost / MySite /关于不工作 - index.php working but http://localhost/MySite/about not working Apache2 - 为什么“http://localhost/index”重定向到“http://localhost/index.php”? - Apache2 - why “http://localhost/index” redirect to “http://localhost/index.php”? 下载文件后,重定向到index.php - After file download redirect to index.php url重定向时,localhost中缺少Index.php文件? - Index.php file is missing in localhost while url is redirecting? htaccess RewriteRule重定向到index.php - htaccess RewriteRule redirects to index.php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM