我正在将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";
}
答案 0 :(得分:0)
Codeigniter对于您可以上传的文件数量没有限制,但是您是否一次上传多个文件,以便达到上传文件大小的限制?在CI配置或服务器配置中。
EDIT!
尝试使用$ this-> upload-> display_errors()根据CI查看出错的地方。我现在的猜测是文件名已经存在,但我很好看看你得到了什么。
第二次编辑!
在您的配置中或加载上载类之前,您可以设置以下设置:max_filename_increment。当overwrite设置为FALSE时,使用此选项设置CodeIgniter附加到文件名的最大文件名增量。
$conf['max_filename_increment'] = // What ever number you think is reasonable
解决这个问题,你应该再次参加:)
第三次编辑!但是,如果您愿意,我当然会告诉您如何编辑课程;
在CI系统的文件夹库中,您可以找到文件Upload.php。在最新版本中,您可以在第390行找到函数set_filename()。向下滚动到第406行,您应该看到
for ($i = 1; $i < 100; $i++)
这是一个循环,它使得文件名递增的转动太少。将100交换为新号码,然后重试。
for ($i = 1; $i < 1000; $i++)
这将比以前循环十倍,但我想限制是为了提高性能所以请在编辑之前和之后检查您的响应时间以及上传同名的3-500个文件?
此致