如何上传开放和读取大(20 mb)csv文件?

时间:2012-12-27 06:32:49

标签: php jquery mysql

我正在处理csv文件上传,我需要上传大型csv文件然后需要插入带有字段映射的数据库。我这样做是使用Jquery它没有显示任何错误只是将网址显示为红色成为firbug 。我没有得到什么问题?这是我的剧本。

    <script src="js/jquery.form.js"></script> 
    <script src="js/create_input.js"></script>
    <script> 
        $(document).ready(function() { 
            $('#UploadForm').on('submit', function(e) { 
                e.preventDefault();
                var value= $("#valS").val();
                var host=$('#host').val(); 
                //alert(host);
                $(this).ajaxSubmit({
                    type: "POST",
                    url: host+"views/excel_file_import.php",
                    data: {value: value},
                    success: function(html){   
                    $('#Exceloutput').html(html);  
                    }
                });  
            });
        }); 

    $(document).ready(function() { 
    $("#updatefields").click(function(){ 
    var arrayOfValues = $(".bookDetails select").map(function (i, el) { return      $(el).val(); }).get();
    var fileName= $("#excelfile").val(); 
    var csvState= $("#state_csv").val(); 
    var host=$('#host').val(); 
    $.ajax({  
        type: "POST",  
        url: host+"views/update_fields.php",  
        data:{str:arrayOfValues, fileName:fileName, csvState:csvState}, 
        success: function(msg){  
            $('#fieldUpdate').html(msg);  
            }  
         });

    return false; 

    });
    }); 
    </script> 
    <?php
    $host=$_SERVER['HTTP_REFERER'];
    $url=substr($host,0,-9);
    ?>
   <input type="hidden" value="<?php echo $url; ?>" id="host">
   <h1 class="page-title">Upload Csv File</h1>
   <div class="container_12 clearfix leading">
   <div class="grid_12" id="edit-form">


    <form action="<?php echo $url; ?>views/excel_file_import.php" method="post"     enctype="multipart/form-data" id="UploadForm" class="form has-validation">

      <div class="clearfix">
               <label for="form-upload" class="form-label">Upload File<em>*</em></label>
               <div class="form-input">
                   <input type="file" size="50" class="text" id="excelfile" name="excelfile" required="required"/>
                   <input type="hidden" size="50" class="text" id="valS" name="valS"  value="1" required="required"/>
               </div>
    </div>

     <div class="form-action clearfix">
             <button class="button class-button" type="submit"   id="SubmitButton">Upload</button>
             <button class="button class-button" type="submit" id="updatefields" name="updatefields">UpdateExcel</button>
     </div>


    </form>
    <div id='fieldUpdate'>
    </div>
    <div id='Exceloutput'>
    </div>

    </div>
     </div>

这是excel_file_import.php代码。

<?php
include("../common/connection.php");
if(isset($_POST))
{
    $database= "test2";
    $filename = 'test-'.$_FILES['excelfile']['name'];
    $value= $_POST['value'];
    $copy= move_uploaded_file($_FILES["excelfile"]["tmp_name"],"../files/".$filename);
    if($copy)
    { echo "Upload Success";?>

<?php
}

}
?>

3 个答案:

答案 0 :(得分:0)

您是否尝试过在php.ini文件中增加文件上传限制:

file_uploads = On
upload_max_filesize = 20M //needs to be in {x}M format

在此处查看更多信息:

  1. http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
  2. http://davidwalsh.name/increase-php-file-upload-limit-using-php-ini
  3. http://wiki.lunarpages.com/Increase_php.ini_Upload_Limit
  4. http://www.radinks.com/upload/config.php

答案 1 :(得分:0)

我正在使用jQuery这样做。它没有显示任何错误。它只是将网址显示为红色成为冷杉

两个文件都位于同一个域中吗? HTML和PHP都? Firebug显示红色网址,因为通常不允许跨域ajax请求

答案 2 :(得分:0)

为了在服务器上上传大文件,请在php.ini文件中检查这些设置,如果你没有访问php.ini,你可以将其更改为htaccess文件。根据你的要求增加这些文件上传的值。

max_input_time 1000 max_execution_time 1000 post_max_size 1000M max_file_uploads 50 upload_max_filesize 1000M