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

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


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.
$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')
///// 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;

Why not use the fileupload library that comes with CodeIgniter?

PHP Code:
$config['upload_path'] = $pathToUpload '/';
$config['allowed_types'] = '*';
$config['overwrite'] = TRUE;

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

Theme © iAndrew 2016 - Forum software by © MyBB