I've been trying to do a multi file upload with codeigniter 1.7. I'm having issues to say the least!
I know its an old version but that's what I've got to work with.
Can I loop the $_FILES array and upload each one? It doesn't seem to work.
Heres what I've got?
$dir_name = $this->input->post('dir');
$file_path = "./system/application/views/courses/course/";
$full_file_path = $file_path . $dir_name;
if (!file_exists($full_file_path)) {
mkdir($full_file_path, 0777, true);
}
$config['upload_path'] = $full_file_path;
$config['allowed_types'] = 'php|js|html';
$this->load->library('upload');
foreach ($_FILES as $files => $fileObject) //
{
if (!empty($fileObject['name']))
{
$this->upload->initialize($config);
if (!$this->upload->do_upload($files))
{
$errors = $this->upload->display_errors();
}
else
{
echo "It worked";
}
}
}
Is this possible?
This code runs but doesn't upload the files?!
Hope This will help
$name_array=array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key => $value)
{
for ($s = 0; $s < $count; $s++)
{
$_FILES['userfile']['name'] = $value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = "uploads/item_images/itemimage/original/";
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '8000';
$config['max_width'] = '10240';
$config['max_height'] = '7680';
$this->load->library('upload', $config);
if ($this->upload->do_upload("image"))
{
$data = $this->upload->data();
if ($this->image_moo->errors)
{
print $this->upload->display_errors();
}
else
{
$name_array[] = $data['file_name'];
} } } }
Yes, can loop through $_FILES... although you probably shouldn't name an array an "object", it's a little confusing.
Here's a user manual I found, specifically for the uploads in 1.7, it appears to be substantially similar to 3.0.3. http://www.standoffsystems.com/ci/user_guide/libraries/file_uploading.html
First, make sure your destination folder is set to 777
your config
is outside the foreach()
and the $this->upload->initialize($config);
is inside, you don't need to initialize it each time since the $config
items are, essentially, static. This isn't likely to fix your issue though.
Try this instead:
$config['upload_path'] = $full_file_path;
$config['allowed_types'] = 'php|js|html';
$this->load->library('upload', $config);
foreach (){
$this->upload->initialize($config); <-- remove this
...
}
I see you're not echoing out any errors, what happens if you do?
echo $this->upload->display_errors();