I am trying to test if multiple files exist by the URL in PHP with a foreach loop.
For some reason i am only appending the last URL to the array and I cannot find out why.
It should print out like:
TEST.COM/sky.jpg exists.
TEST.COM/water.jpg doesnt exist
TEST.COM/trees.jpg exists.
But the last url only appends, which is trees.jpg
.
Here is my code, I'm not too well at PHP. Maybe a little misunderstanding of the foreach
function.
Where have I gone wrong?
$neg = 'doesnt exist';
$exists = 'exists.';
$file = $_POST['URL'];
$terms = array('sky.jpg','water.jpg','trees.jpg');
reset($terms);
$list = array();
foreach ($terms as &$i){
$fullurl = $file.$i;
$file_headers = @get_headers($fullurl);}
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
array_push($list,$fullurl." ".$neg);}
else {array_push($list,$fullurl." ".$exists);}
foreach ($list as &$x){echo $x;}
?>