Remove filenames with 'not allowed' extensions in an array in PHP
Get the solution ↓↓↓Solution:
try this code, you can add mode allowed extensions in$allowed
array, but without dot
$f = array('file1.jpg', 'file2.png', 'file3.bmp', 'file4.zip', 'file5.txt' );
$allowed = array('jpg','png');
echo "<pre>before removing";
print_r($f);
echo "</pre>";
foreach($f as $k=>$v){
$ext = end(explode(".",$v));
if(!in_array($ext,$allowed)){
unset($f[$k]);
}
}
echo "<pre>after removing";
print_r($f);
echo "</pre>";
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered in
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.