CSV文件上传问题

时间:2012-04-27 10:24:59

标签: php

我正在尝试使用php中的文件上传程序控件上传CSV文件,如果文件大小超过10 MB则没有上传它只会挂起页面执行。我已经设置了

  

ini_set(“upload_max_filesize”,“50M”); ini_set(“post_max_size”,   “50M”);

在页面上,仍然没有任何运气给我。如果我上传文件高达8 MB它工作正常。我很困惑为什么isue仍然有事件我已经设置相关文件大小上传同一页。请帮我。

提前致谢,

以下是我的PHP代码

<?php

  set_time_limit(0); ini_set('display_errors', 1); ini_set( "upload_max_filesize", "100M" );   ini_set( "post_max_size", "100M" );


ini_set( "session.save_handler", "files" ); session_start(); header ('Last-Modified: '.gmdate("D, d M Y H:i ").' GMT');   header ('Expires: '.gmdate("D, d M Y H:i ").' GMT');   header ('Cache-Control: no-cache, must-revalidate');   header ('Pragma: no-cache');

if ($_FILES['import']['error'] == UPLOAD_ERR_OK )           {
            $tmpName = $_FILES['import']['tmp_name'];
            $csvName = $_FILES['import']['name'];
            $mime = $_FILES['import']['type'];
            $validMimes = array('text/csv');


            if(!strpos($csvName, '.csv'))
            {
                $errMsg = ' [' . $csvName . '] is INVALID csv file (<i>csv only</i>)';
            }

            if ( is_uploaded_file($tmpName) && !isset($errMsg) ) // upload photo file then save author if uploaded file is VALID
            {
                // upload photo to server
                $filename = 'uploads/products/';

                $pathParts = pathinfo($csvName);

                $photoFile = _generateUniquePhoto($pathParts['extension']);

                //move_uploaded_file($tmpName, $filename . $photoFile);

                //chmod($filename . $photoFile, 0777);

                // save to database
                $fullfilename = $filename.$photoFile;
                //$this->data['University']['add_logo'] = $photoFile;

                $ftp_server = "XXXXX";
                $ftp_user_name = "XXXX";
                $ftp_user_pass = "XXXXX";


                // set up basic connection
                $conn_id = ftp_connect($ftp_server); 

                // login with username and password
                $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

                // check connection
                if ((!$conn_id) || (!$login_result)) 
                { 
                       echo "FTP connection has failed!";
                       echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
                       exit; 
                } else 
                {
                       //echo "Connected to $ftp_server, for user $ftp_user_name";
                }

                // upload the file
                $destination_file1 = "httpdocs/volhub/client/$fullfilename";
                $sourcefile1 = "$tmpName";
                $upload = ftp_put($conn_id, $destination_file1, $sourcefile1, FTP_BINARY);  // line 30

                // check upload status

                ftp_close($conn_id); }

2 个答案:

答案 0 :(得分:1)

您无法使用ini_set()修改这些设置,因为它们是PHP_INI_PERDIR

您必须在php.ini本身或使用(假设Apache).htaccess文件中更改它们。当您的脚本开始执行并且调用ini_set()时,PHP已经决定接受或拒绝该请求。

See here了解有关使用.htaccess更改设置的详细信息。

答案 1 :(得分:0)

我也有这个并且找不到解决方案,过了一段时间我决定使用带有“分块”功能的javascript上传器。您可以在plupload.com找到我正在使用的那个。在我看来,这很容易合作。