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.