【问题标题】:Why the upload cancels and the server close the connection为什么上传取消并且服务器关闭连接
【发布时间】:2012-08-01 02:56:17
【问题描述】:

我正在上传一个 14 兆字节的视频文件,这是我的配置:

ini_set("max_execution_time", "180");
ini_set("upload_max_filesize", "300M");
ini_set("post_max_size", "300M");
ini_set("memory_limit", "300M");

我已经把它放在 index.php 文件和我的 .htaccess 中:

addDefaultCharset UTF-8

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|uploads|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

所以问题是当我上传视频文件时,在状态栏中我看到百分比递增 1%、2%、3%、4%、5%、6%、7%、8%、9%, 10%、11%、12%、13 美元、14%、15%……等等。

当它达到 19-20% - 它取消到 0%,然后再次开始增加 1%、2%、3%,我不明白为什么会发生这种情况?有人可以解释一下吗?你有过这样的事情吗?怎么解决?,文件大约有 14 兆字节....

<form action="" method="post" enctype="multipart/form-data">
<p>title</p>
<input type="text" name="title">
<p>video file</p>
<input type="file" name="video">
<p>cover file</p>
<input type="file" name="pic">
<p>description</p>
<textarea name="short_desc" style="width: 500px; height: 150px;"></textarea>
<p><input type="submit" value="add video" name="add"></p>
</form>

这是html上传表单...

这是codeIgniter中的上传方法:

public function add_video()
{

    if(!$this->is_admin){return false;}

    if(!$this->input->post('add')){
    $data['content'] = $this->load->view(ADMIN.'video/add', null, true);
    $this->load->view(ADMIN.'layout', $data);
    }
    else
    {

        $num = 1;
        if(is_dir("./uploads/videos/video".$num))
        {

            while(true)
            {
                $num++;
                if(!is_dir("./uploads/videos/video".$num))
                {

                    mkdir("./uploads/videos/video".$num);
                    break;
                }
            }
        }
        else
        {

            mkdir("./uploads/videos/video".$num);
        }


    $config['upload_path'] = "./uploads/videos/video".$num;
    $config['allowed_types'] = 'mov|mpeg|mp3|mp4|avi|flv';;
    $config['max_size'] = '0';
    $config['max_width']  = '0';
    $config['max_height']  = '0';

    $this->load->library('upload', $config);
    if ($this->upload->do_upload('video'))
    {

         $data = array('upload_data' => $this->upload->data());
         $file_name = $data['upload_data']['file_name'];

         $video_path = "./uploads/videos/video".$num.'/'.$file_name;
         $config['allowed_types'] = 'jpg|png|gif|bmp';
         $this->upload->initialize($config);
         if ($this->upload->do_upload('pic'))
         {

             $data = array('upload_data' => $this->upload->data());
             $file_name = $data['upload_data']['file_name'];
             $config['image_library'] = 'gd2';
             $config['source_image'] = "./uploads/videos/video".$num.'/'.$file_name;
             $config['create_thumb'] = FALSE;
             $config['maintain_ratio'] = FALSE;
             $config['width'] = 150;
             $config['height'] = 100;

             $this->load->library('image_lib', $config); 

             $this->image_lib->resize();

             $image_path = $config['source_image'];



         }
         else
         {
            redirect(base_url().'admin/add_video');

         }
    }
    else
    {
        redirect(base_url().'admin/add_video');
    }
    $data = array();

    $data['title'] = $this->input->post('title');
    $data['short_desc'] = strip_tags($this->input->post('short_desc'));
    $data['video_path'] = $video_path;
    $data['image_path'] = $image_path;
    $data['date'] = date('y-m-d h:i:s');
    $this->load->model('video_model');
    $this->video_model->add($data);

    redirect(base_url().'admin/add_video');


    }

}

抱歉,代码太多了,但你能在这里找到一些导致该问题的错误吗?

【问题讨论】:

  • 一些想法??它发生在我的主机中,但在我的本地机器上它上传得很好,我不知道发生了什么
  • 检查 memory_limit 设置,上传的文件在上传时存储在内存中。
  • 3 分钟后是否失败? ini_set("max_execution_time", "180"); 或许应该更大?
  • 您的主机可能阻止了 ini_set 函数。听起来您的文件正在达到大约 3 兆并放弃。这似乎是系统管理员可能对共享主机施加的那种硬限制。
  • @MisterPHP,不是主机,PHP RTS。这些是 PHP_INI_PERDIR,这意味着不能使用 ini_set。但是托管商确实为“合理使用”配置了共享服务。使用 FTP 是它的一项管理功能。

标签: php .htaccess codeigniter file-upload


【解决方案1】:

您是否检查过您的 ini_set() 是否有效?每次调用时都尝试回显 ini_set() 。如果设置了值,则返回旧值(如果无法设置新值,则返回 false)。

也可以尝试测试:

set_time_limit(0);  // it will make the time limit unlimited

【讨论】:

    猜你喜欢
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 2020-11-22
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多