What I have here is a delete multiple file function in codeigniter. I need to merge or concat the value only of associative array. The value of both array was the file name and file extension of an image/file. I used md5 to change the name of the file.
This is my code
public function delete_files(){
$filesCount = count($_FILES['file_certificate']['name']);
$file_certificate = [];
$y = 0;
for($i = 0; $i < $filesCount; $i++){
$_FILES['file_certificates']['name'] = $_FILES['file_certificate']['name'][$i];
$_FILES['file_certificates']['type'] = $_FILES['file_certificate']['type'][$i];
$_FILES['file_certificates']['tmp_name'] = $_FILES['file_certificate']['tmp_name'][$i];
$_FILES['file_certificates']['error'] = $_FILES['file_certificate']['error'][$i];
$_FILES['file_certificates']['size'] = $_FILES['file_certificate']['size'][$i];
$oldname = $_FILES["file_certificates"]['name'];
$file_ext[] = pathinfo($oldname,PATHINFO_EXTENSION);
$file_ray[] = trim(strtolower(md5(time().$oldname)));
$result = array_combine($file_ray, $file_ext);
}
$path = FCPATH . 'uploads/certificate/';
array_map('unlink', $result);
}
Here's my array right now
I need it like this
Array
(
[0] => 46eced0ea722a94160d53b4abbb10381.jpg
[1] => 4f9ca54fa1daa022dc31b991a673cab7.pdf
)
And also I never try this if its works deleting a multiple file via this code
$path = FCPATH . 'uploads/certificate/'; //path file location
array_map('unlink', $result);
Thank you.
I got this done using foreach.
$path = FCPATH . 'uploads/certificate/';
$data = array();
foreach( $file_ray as $index => $code ) {
$value = $path.$code.'.'.$file_ext[$index];
$data[] = $value;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.