Welcome Guest, Not a member yet? Register   Sign In
Problem creating folder and uploading files.
#1

(This post was last modified: 01-20-2016, 01:43 PM by chocovo.)

Hello,

In my form, When I click "Submit" I am trying to create a folder and upload several input files into it.

In this moment, creating the folder is ok but I have an error with the upload part.

Actually I don't understand how "upload" works and I'm stuck.

Thank you for the help.
This is part of the code:
PHP Code:
function addexample() { // When I click Submit.
        
$this->load->helper(array('form''url','text'));
        
$this->load->library('upload');   
        
        
$data = array(
            
'example_name' => $this->input->post('example_name'),
            
'example_address' => $this->input->post('example_address'),
            
'example_image_1' => $this->input->post('example_image_1'),
            
'... some more fields',
            
'example_image_2' => $this->input->post('example_image_2'),
            
'... some more fields',
            
'example_image_3' => $this->input->post('example_image_3')
        );
        
$this->db->insert('exampletable'$data);
        
        
///// Now uploading the 3 images files
        // Creating folder 
        
$lastID $this->db->insert_id();    
        
$slug url_title(convert_accented_characters($this->input->post('example_name')), 'dash'TRUE);
        
$folderName $lastID.'-'.$slug;
        
$pathToUpload './assets/upload/files/examples/' $folderName;
        if (!
file_exists($pathToUpload)) $create mkdir($pathToUpload0777); // Folder is created.
        
        //Uploading files to folder
        // > I don't understand exactly how does it work and this part give me error.
        
$tempFile $_FILES['file']['tmp_name'];
        
$fileName $_FILES['file']['name'];
        
$targetPath getcwd() . $pathToUpload.'/';
        
$targetFile $targetPath $fileName;
        
move_uploaded_file($tempFile$targetFile);
    } 
Reply
#2

Why not use the fileupload library that comes with CodeIgniter?

PHP Code:
$config['upload_path'] = $pathToUpload '/';
$config['allowed_types'] = '*';
$config['overwrite'] = TRUE;
$this->load->library('upload',$config);
$this->upload->do_upload(); 

The do_upload method does all the work. It detects files that are in $_FILES.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB