Reputation: 1751
I have a problem with my multi image upload.
The code
function tester($yourUniqueId){
$this->load->library('upload');
for($i=0; $i<count($_FILES); $i++)
{
$_FILES['userfile']['name'] = $_FILES['filename']['name'][$i];
$_FILES['userfile']['type'] = $_FILES['filename']['type'][$i];
$_FILES['userfile']['tmp_name'] = $_FILES['filename']['tmp_name'][$i];
$_FILES['userfile']['error'] = $_FILES['filename']['error'][$i];
$_FILES['userfile']['size'] = $_FILES['filename']['size'][$i];
$path = './uploads/' . $yourUniqueId;
mkdir($path);
$config['file_name'] = "kep_" . $i;
$config['upload_path'] = $path;
$config['allowed_types'] = 'jpg|jpeg|png';
$config['max_size'] = '0';
$config['overwrite'] = FALSE;
$this->upload->initialize($config);
if($this->upload->do_upload())
{
$error += 0;
}else{
$error += 1;
}
}
if($error > 0){
return FALSE;
}else{
return TRUE;
}
}
Its a bit strange, because, it it returns false, and i give it an echo
if($error > 0){
echo 'Something went wrong'; //just for a test
return FALSE;
Doesnt it sopose to show the echo?
I cant make it work.
Is there something worng with the code?
Could please someone give me a hint? I cant see it anywhere
Upvotes: 1
Views: 380
Reputation: 9547
Try replacing this:
if($this->upload->do_upload())
{
$error += 0;
}else{
$error += 1;
}
With this:
if ( !$this->upload->do_upload())
{
$error++;
echo $this->upload->display_errors();
}
That should tell you what went wrong. You also might want to wrap the mkdir() function just in case the directory does exist (I don't know how PHP handles it otherwise--might be returning early):
if ( !is_dir($path))
{
mkdir($path, 0777, TRUE); // make it writable!
}
Upvotes: 1