Problem:
I am currently working on integrating FilePond.js into my CodeIgniter project for handling file uploads. However, I've encountered an issue where the FilePond upload functionality doesn't seem to work as expected. I've followed the documentation and implemented the necessary code, but files are not being uploaded successfully.
Details:
- I'm using CodeIgniter version 3.
- FilePond.js version: 4.30.6
- PHP version: 7.3
Code snippets:
Here is a simplified version of my CodeIgniter controller and view files:
Controller:
FilePond.create(document.getElementById('validIdFile'), {
server: {
process: {
url: base_url + 'upload-id-file',
method: 'POST',
withCredentials: true,
headers: {},
onload: (response) => {
console.log(response);
},
onerror: (response) => {
console.error(response);
},
ondata: (formData) => {
return formData;
}
},
},
});
Below is my serverside code
public function handleFilePondUpload()
{
$targetDir = FCPATH . "uploads/diverseservices/validateid/";
if (!is_dir($targetDir)) {
mkdir($targetDir, 0777, true);
}
$config['upload_path'] = $targetDir;
$config['allowed_types'] = 'jpg|jpeg|png|pdf';
$config['max_size'] = 10240;
$this->load->library('upload', $config);
if ($this->upload->do_upload('validIdFile')) {
$uploadData = $this->upload->data();
$filePath = "uploads/diverseservices/validateid/" . $uploadData['file_name'];
echo json_encode(['success' => true, 'file_path' => $filePath]);
} else {
echo json_encode([
'success' => false,
'error' => $this->upload->display_errors('<p>', '</p>'),
]);
}
}
I have followed the FilePond.js documentation and integrated it into my CodeIgniter project. However, when I try to upload a file using FilePond, the upload process doesn't seem to work. There are no error messages in the console, and the server doesn't receive any files.
The issue seems as this is going null or in payload any of the file information is null in $uploadData = $this->upload->data(); { "file_name": "", "file_type": "", "file_path": "", "full_path": "", "raw_name": "", "orig_name": "", "client_name": "", "file_ext": "", "file_size": null, "is_image": false, "image_width": null, "image_height": null, "image_type": "", "image_size_str": "" }