0

我正在尝试使用 php 中的文件上传器控件上传 CSV 文件,如果文件大小超过 10 MB,它不会被上传,它只会挂起页面执行。我已经设定

ini_set("upload_max_filesize", "50M"); ini_set("post_max_size", "50M");

在页面上,我仍然没有运气。如果我上传的文件最大为 8 MB,它的工作正常。我对为什么问题仍然存在感到困惑,我在同一页面上做了与文件大小上传相关的设置。请帮我。

提前致谢,

以下是我的 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); }
4

2 回答 2

1

您不能修改这些设置,ini_set()因为它们是PHP_INI_PERDIR.

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

有关使用 更改设置的更多信息,请参见此处.htaccess

于 2012-04-27T10:29:58.153 回答
0

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

于 2012-04-27T10:27:53.853 回答