0

我正在将 CodeIgniter 用于我拥有的 iPhone 应用程序。该应用程序允许用户将图像分享给特定的个人。效果很好,但似乎在将一定数量的图片发送给个人后,帖子无法上传。我想知道 CodeIgniter 中是否有什么东西导致了这个问题以及如何解决它。

这是我们的配置文件的一部分:

$config['proxy_ips'] = '';

$config['upload_group_path'] = "./upload/group";
$config['upload_user_path'] = "./upload/users";
$config['upload_photo_path'] = "./upload/photo";
$config['upload_video_path'] = "./upload/video";
$config['upload_weblink_path'] = "./upload/weblink";
$config['upload_drawing_path'] = "./upload/drawing";
$config['upload_text_path'] = "./upload/text";

$config['upload_movietype'] = 'mp4|flv|3gp|wmv';
$config['upload_moviesize'] = 100 * 1024; // 100M

$config['upload_alltype']   = '*';
$config['upload_allsize']   = 100 * 1024; // 100M

$config['upload_imgtype']   = 'gif|jpg|png|bmp|jpeg|jpe';
$config['upload_imgsize']   = 5 * 1024; // 5M
$config['upload_thumb_mw']  = '80';
$config['upload_thumb_mh']  = '60';

$config['upload_kmltype']   = 'kml';
$config['upload_kmlsize']   = 10 * 1024; // 10M

$config['main_category'] = array(
'user'  =>  'Users',
'photo' =>  'Photos',
);

$config['difficulty'] = array(
'Easy'      =>  'Easy',
'Moderate'  =>  'Moderate',
'Difficult' =>  'Difficult',
);

$config['max_count_per_page'] = 5;

$config['thumb_name'] = "_thumb";
$config['photo_name'] = "_photo";

以及我们的 api 文件的一部分(在 xcode 的输出中绘制错误“上传失败”):

    $tbl_name = "posts";
    $new_idx = $this->api_m->get_next_insert_idx($tbl_name);
    if (isset($_FILES['datafile']) && $_FILES['datafile']['name'] != '') {
        $conf = array();
        $conf['upload_path']    = $this->api_m->get_upload_path($postType, $ownerID."_".$format);
        $conf['allowed_types']  = $this->config->item('upload_alltype');
        $conf['max_size']       = $this->config->item('upload_allsize');
        $conf['overwrite']      = FALSE;
        $conf['remove_spaces']  = TRUE;

        if (!file_exists($conf['upload_path'])) {
            mkdir($conf['upload_path']);
        }

        $this->upload->initialize($conf);

        if ($this->upload->do_upload('datafile')) {

            $fileinfo = $this->upload->data();
            if ($fileinfo['file_size'] > 0) {
                $postURL = base_url().substr($conf['upload_path'], 2)."/".$fileinfo['file_name'];
                if ($postType == "video") {
                    $referenceData = base_url().substr($conf['upload_path'], 2)."/".$fileinfo['file_name'];
                    if (isset($_FILES['thumbfile']) && $_FILES['thumbfile']['name'] != '') {
                        $conf = array();
                        $conf['upload_path']    = $this->api_m->get_upload_path($postType, $ownerID."_".$format);
                        $conf['allowed_types']  = $this->config->item('upload_alltype');
                        $conf['max_size']       = $this->config->item('upload_allsize');
                        $conf['overwrite']      = FALSE;
                        $conf['remove_spaces']  = TRUE;

                        if (!file_exists($conf['upload_path'])) {
                            mkdir($conf['upload_path']);
                        }

                        $this->upload->initialize($conf);
                        if ($this->upload->do_upload('thumbfile')) {
                            $fileinfo = $this->upload->data();
                            $baseName = $this->api_m->_img_resize($postType, $fileinfo, $fileinfo['raw_name'], $new_idx);
                            $postURL = base_url().substr($conf['upload_path'], 2)."/".$baseName;
                            $baseName = $this->api_m->_img_thumb($postType, $fileinfo, $fileinfo['raw_name'], $new_idx);
                            $thumbURL = base_url().substr($conf['upload_path'], 2)."/".$baseName;
                        }
                    }
                } else {
                    $baseName = $this->api_m->_img_thumb($postType, $fileinfo, $fileinfo['raw_name'], $new_idx);
                    $thumbURL = base_url().substr($conf['upload_path'], 2)."/".$baseName;
                }
                $uploadMsg = "success";
            }
        } else {
            $uploadMsg = "fail to upload";
        }
    } else {
        $uploadMsg = "select the post data";
    }
4

1 回答 1

0

Codeigniter 对您可以上传的文件数量没有限制,但是您是否一次上传多个文件,这样您可能会达到上传文件大小的限制?在 CI 配置或服务器配置中。

编辑!
尝试使用 $this->upload->display_errors() 根据 CI 查看问题所在。我现在的猜测是文件名已经存在,但我很想看看你得到了什么。

第二次编辑!
在您的配置中或在加载上传类之前,您可以设置设置:max_filename_increment。当 overwrite 设置为 FALSE 时,使用它来设置 CodeIgniter 附加到文件名的最大文件名增量。

$conf['max_filename_increment'] = // What ever number you think is reasonable

解决这个问题,你应该很高兴再去一次:)

第三次编辑!
很抱歉,该设置尚不可用。因此,要么您必须在您的应用程序文件夹中添加自己的上传类,否则您将不得不在系统中编辑上传类。请注意,不建议更新系统文件夹中的任何内容,因为如果您稍后更新 CI 版本,它将被覆盖。

但是,如果您愿意,我当然会告诉您如何编辑课程;

在 CI 系统的文件夹库中,您可以找到文件 Upload.php。在最新版本中,您可以在第 390 行找到函数 set_filename()。向下滚动到第 406 行,您应该会看到

for ($i = 1; $i < 100; $i++)

这是一个循环,它的文件名增加的次数太少。将 100 换成新号码,然后重试。

for ($i = 1; $i < 1000; $i++)

这将比以前循环十倍,但我猜性能有限制,所以在编辑它之前和之后以及上传 3-500 个同名文件时检查你的响应时间?

问候

于 2013-04-30T11:28:27.030 回答