Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php获取内容图像文件夹svg_Php_Wordpress_Svg - Fatal编程技术网

php获取内容图像文件夹svg

php获取内容图像文件夹svg,php,wordpress,svg,Php,Wordpress,Svg,我正在尝试从文件夹中获取svg文件 尝试了以下方法,但似乎都不起作用: <?php $directory = get_bloginfo('template_directory').'/images/myImages/'; $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); while ($it->valid()) { //Check the file exi

我正在尝试从文件夹中获取svg文件

尝试了以下方法,但似乎都不起作用:

<?php   
$directory = get_bloginfo('template_directory').'/images/myImages/';      
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
while ($it->valid()) { //Check the file exist
    if (!$it->isDot()) { //if not parent ".." or current "."
        if (strpos($it->key(), '.php') !== false
           || strpos($it->key(), '.css') !== false
           || strpos($it->key(), '.js') !== false
        ) {
        echo $it->key() . '<br>';
        }
    }
}
?>
以及:

以及:

以及:

$directory=get_bloginfo('template_directory')。“/images/myImages/”;
$images=glob($directory.*.svg”);
回声';
打印(图像);
回声';
echo$directory.abnamro.svg“>”;
foreach($images作为$image)
{
回波图像;
}
我有点迷路了。我可能认为还有别的问题。
还检查了用户的权限,但一切正常。 我在本地机器上用MAMP运行Wordpress


有什么想法吗?

试试下面的功能,为了清楚起见,我已经记下了。一些亮点是:

  • 您可以在目录迭代器中跳过开头的点
  • 如果路径不存在,则可能触发致命错误(在本例中,这就是问题所在,您使用的是域根路径而不是服务器根路径[
    ABSPATH
    ])
  • 您可以选择用于筛选文件的扩展名类型

  • 使用:

    Array
    (
        [0] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img1.svg
        [1] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img2.svg
        [2] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img3.svg
        [3] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img4.svg
    )
    
    如果路径不存在,它现在会通过系统错误的方式告诉您该路径不存在。如果它没有抛出致命错误并且结果为空,那么您确实遇到了一些奇怪的问题

    如果一切顺利,您应该得到如下结果:

    如果路径无效,将抛出:

    致命错误:文件夹不存在。无法返回任何文件路径。在/data/19/2/133/150/3412/user/12321/htdocs/domain/index.php中,联机123


    请尝试下面的功能,为了清晰起见,我已经做了注释。一些亮点包括:

  • 您可以在目录迭代器中跳过开头的点
  • 如果路径不存在,则可能触发致命错误(在本例中,这就是问题所在,您使用的是域根路径而不是服务器根路径[
    ABSPATH
    ])
  • 您可以选择用于筛选文件的扩展名类型

  • 使用:

    Array
    (
        [0] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img1.svg
        [1] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img2.svg
        [2] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img3.svg
        [3] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img4.svg
    )
    
    如果路径不存在,它现在会通过系统错误的方式告诉您该路径不存在。如果它没有抛出致命错误并且结果为空,那么您确实遇到了一些奇怪的问题

    如果一切顺利,您应该得到如下结果:

    如果路径无效,将抛出:

    致命错误:文件夹不存在。无法返回任何文件路径。在/data/19/2/133/150/3412/user/12321/htdocs/domain/index.php中,联机123



    您是否尝试过使用scandir获取文件夹中的文件列表并在其中循环?还没有循环。我尝试过并检查了数组中的值,但数组为空。不会出现任何错误。它是否可能在错误的文件夹中查找?是否获取了\u bloginfo('template\u directory'))返回正确的文件夹?是的,它使用正确的文件夹。我检查的第一件事;-)所以
    echo是_dir($directory)
    生成
    1
    ?您是否尝试过使用scandir获取文件夹中的文件列表并在其中循环?还没有循环。我尝试过并检查了数组中的值,但数组是空的。不会出现任何错误,也不会出现任何错误。它是否可能在错误的文件夹中查找?是否获得了_bloginfo('template_directory'))返回正确的文件夹?是的,它使用正确的文件夹。我检查的第一件事;-)所以
    echo是_dir($directory);
    生成
    1
    ?谢谢你的解释性回答。它确实给我带来了一个错误。说文件夹不存在。唯一的问题是文件夹确实存在。权限是正确的…我尝试使用绝对路径,但它一直给我错误。这可能是MAMP/本地问题吗?我将其放到网上,看看是什么原因偶尔只是为了确保…..我将函数添加到了我的
    函数中。php
    …虽然我回显了目录并将其直接粘贴到了浏览器中,但没有工作。它会给我一个该文件夹中所有项目的列表…我在这里迷路了。它只会列出扩展名作为参数放入函数中的文件。它说不能找到该文件夹。感谢您的wel解释的答案。它确实给我带来了一个错误。说该文件夹不存在。唯一的问题是该文件夹确实存在。权限是正确的…我尝试使用绝对路径,但它不断给我错误。这可能是MAMP/本地问题吗?我将把它放在网上,然后看看发生了什么请确保…..我已将该函数添加到我的
    函数中。php
    …尽管我已将目录回显并直接粘贴到浏览器中,但仍无法工作。它会为我提供该文件夹中所有项目的列表…我在这里丢失了。它只会列出将扩展名作为参数放入该函数中的文件。它表示找不到该文件夹。
    $dir    = get_bloginfo('template_directory').'/images/myImages/';
    $files = scandir($dir);
    print_r($files);
    
    $directory = get_bloginfo('template_directory')."/images/myImages/";
    $images = glob($directory . "*.svg");
    echo '<pre>';
    print_r($images);
    echo '</pre>';
    echo $directory.'abnamro.svg">';
    foreach($images as $image)
        {
          echo $image;
        }
    
    function getPathsByKind($path,$ext,$err_type = false)
        {
            # Assign the error type, default is fatal error
            if($err_type === false)
                $err_type   =   E_USER_ERROR;
            # Check if the path is valid
            if(!is_dir($path)) {
                # Throw fatal error if folder doesn't exist
                trigger_error('Folder does not exist. No file paths can be returned.',$err_type);
                # Return false incase user error is just notice...
                return false;
            }
            # Set a storage array
            $file   =   array();
            # Get path list of files
            $it     =   new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($path,RecursiveDirectoryIterator::SKIP_DOTS)
            );
            # Loop and assign paths
            foreach($it as $filename => $val) {
                if(strtolower(pathinfo($filename,PATHINFO_EXTENSION)) == strtolower($ext)) {
                    $file[] =   $filename;
                }
            }
            # Return the path list
            return $file;
        }
    
    # Assign directory path
    $directory = str_replace('//','/',ABSPATH.'/'.get_bloginfo('template_directory').'/images/myImages/');
    # Get files
    $files = getPathsByKind($directory,'svg');
    # Check there are files
    if(!empty($files)) {
        print_r($files);
    }
    
    Array
    (
        [0] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img1.svg
        [1] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img2.svg
        [2] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img3.svg
        [3] => /data/19/2/133/150/3412/user/12321/htdocs/domain/images/myImages/img4.svg
    )