如何在codeigniter中添加多个文件 [英] How to add multiple files in codeigniter
问题描述
我在我的项目中使用codeigniter,我面临一个问题,而上传多个文件到数据库。上传的图像未移动到特定文件夹。所以我的文件没有保存在我的数据库。我有附加我的代码下面,请找到下面的附件,告诉我,我失踪。
提前感谢。
模型:
I am using codeigniter in my project, i am facing one problem while uploading multiple files to database. uploaded images was not moving to the particular folder. so my file was not saving in my database. i have attach my code below please find the below attachment and tell me what i am missing. Thanks in advance. Model:
public function myfunction(){
$config = array(
'upload_path' => 'charity_gallery',
'max_size' => 2000 * 2000,
'allowed_types' => 'gif|jpeg|jpg|png',
'overwrite' => true,
'remove_spaces' => true);
$images = array();
$this->load->library('upload', $config);
$files = $_FILES;
$count = count($_FILES['charity_image']['name']);
echo $count;
for ($i = 0; $i < $count; $i++) {
$_FILES['charity_image']['name'] = $files['charity_image']['name'][$i];
$_FILES['charity_image']['type'] = $files['charity_image']['type'][$i];
$_FILES['charity_image']['tmp_name'] = $files['charity_image']['tmp_name'][$i];
$_FILES['charity_image']['error'] = $files['charity_image']['error'][$i];
$_FILES['charity_image']['size'] = $files['charity_image']['size'][$i];
$fileName = $_FILES['charity_image']['name'];
$images[] = $fileName;
$config['file_name'] = $fileName;
$imgName = 'charity_gallery/'.$fileName;
//echo $imgName;
$this->upload->initialize($config);
//echo "hello"."INSERT INTO `charity_gallery` (charity_id, image_name, created_on) VALUES ('$cid', '$imgName', '$createdOn')";
if ($this->upload->do_upload('charity_image')) {
echo "how"."INSERT INTO `charity_gallery` (charity_id, image_name, created_on) VALUES ('$cid', '$imgName', '$createdOn')";
$query = $this->db->query("INSERT INTO `charity_gallery` (charity_id, image_name, created_on) VALUES ('$cid', '$imgName', '$createdOn')");
}
}
$aff = $this->db->affected_rows();
return $aff;
}
Html:
<div class="control-group" style="padding:15px;">
<label class="control-label" for="basicinput" style="padding:10px;">Image Gallery:</label>
<div class="controls">
<div class="input-append span6">
<input type="file" class="span12" placeholder="Upload file" id="charity_image" name="charity_image[]" multiple>
</div>
<div class="span12" style="margin-top: 15px;">
<output id="result" />
</div>
</div>
</div>
在这里,如果我添加共3张图片,意味着只有一个图片被添加和上传。剩余的两个图像未上传。我不知道我在哪里做错了。
In this, If i add totally 3 images means only one image getting added and uploaded. remaining two image was not getting upload. I dont know where i am doing wrong.
推荐答案
您的路径是否正确?
'upload_path'=> 'charity_gallery',
这个文件夹在哪里?尝试 ./ charity_gallery /
。 (请确保具有正确的权限)
Where is located this folder? Try ./charity_gallery/
instead. (make sure to have the correct permissions too)
这篇关于如何在codeigniter中添加多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!