I’m trying to retrieve the filenames of the uploaded files from the $_FILES array but I’m struggling.
print_r($_FILES); clearly works but when I try to loop through $_FILES I’m not getting anything.
Here’s the output I have from print_r($_FILES); after uploading a single file:
Array
(
[files] => Array
(
[name] => Array
(
[0] => testfile.pdf
)
[type] => Array
(
[0] => application/pdf
)
[tmp_name] => Array
(
[0] => /tmp/phpkC2Tsw
)
[error] => Array
(
[0] => 0
)
[size] => Array
(
[0] => 1119353
)
)
)
I've tried looping through the array 2 ways and I'm getting no output. Here's what I have in functions.php so far.
add_action( 'fu_after_upload', 'my_fu_after_upload', 10, 3 );
function my_fu_after_upload( $attachment_ids, $success, $post_id ) {
echo "<pre>";
print_r($_FILES);
echo "</pre>";
$count = count($_FILES['files']);
for($i=0; $i<=$count; $i++) {
if ($_FILES['files'][$i]['size'])
echo $_FILES['files'][$i]['name']."\n";
}
foreach($_FILES['files'] as $file) {
echo $file['name']."\n";
}
}
Ultimately, I'm trying to retrieve the link(s) of any uploaded file(s) immediately after the file(s) are uploaded. But I'm stuck at how to pull the data I need from $_FILES.
Thanks for any help.