php foreach and glob() function

时光总嘲笑我的痴心妄想 提交于 2019-12-10 18:32:48

问题


PHP versione 5.2.*

my function not working :/

images in server, in folder: /public_html/gallery/images

<?php
    foreach(glob('gallery/images/*', GLOB_NOSORT) as $image)   
    {  
        echo "Filename: " . $image . "<br />";      
    }  
?>

any help? what im doing wrong?

error i get is : Warning: Invalid argument supplied for foreach() in /home/a9773555/public_html/gallery/index.php on line 2


回答1:


The problem looks you have put your php file in gallery folder...

/home/a9773555/public_html/gallery/index.php on line 2

if that is the case (if you put index.php in gallery) then try the following:

<?php
    foreach(glob('images/*', GLOB_NOSORT) as $image)   
    {  
        echo "Filename: " . $image . "<br />";      
    }  
?>

Or do the following,

Put your index.php in your /home folder. then...

<?php
    foreach(glob('a9773555/public_html/gallery/images/*', GLOB_NOSORT) as $image)   
    {  
        echo "Filename: " . $image . "<br />";      
    }  
?>

Give it a try. and let me know...



来源:https://stackoverflow.com/questions/19543136/php-foreach-and-glob-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!