0
votes

I have an upload form with mulitple file attachments name="attachment[]"

I need to pass the uploaded file to a function in a class which handles the saving of the file (amongst other actions).

The function:

public function saveFile($userId, $ticketId, $fileType, $fileName, $fileContent) 
{
    // Create directory
    $this->createDirectory($ticketId);

    $file = fopen(FILE_SAVE_PATH . "/" . $ticketId . "/" . $fileName, 'w');
    fwrite($file, $fileContent);
    fclose($file);
}

The loop which is sending the function the data

foreach($_FILES['attachment']['name'] as $index => $value) 
{
      $fw->models->file->saveFile(
                            $si->input->session('bug/userData/id'), 
                            $ticketId, 
                            '', 
                            $_FILES['attachment']['name'][$index],
                            base64_encode($_FILES['attachment']['tmp_name'][$index]));
}

As you can see I've tried base64_encode, the image is "saved" but it is corrupt when i try open it.

Thank you.

2
corrupt = base64 encoding the temporary file name and expecting it to be an imagedogmatic69

2 Answers

1
votes

look at this http://www.tizag.com/phpT/fileupload.php seems you are missing a few of the finer details of saving an upload. base64_encode($_FILES['attachment']['tmp_name'][$index])); is not the file

try print_r($_FILES) before doing anything to the array.

0
votes
public function saveUploadedFile($userId, $ticketId, $fileType, $fileName, $tempFile) 
{
    //create directory
    $this->createDirectory($ticketId);

    $savePath = FILE_SAVE_PATH . "/" . $ticketId . "/" . $fileName;
    return (move_uploaded_file($tempFile, $savePath)) ? TRUE : FALSE;   
}

Fixed it in the end by passing the function the temp path, thank you

$_FILES['attachment']['tmp_name'][$index]