【问题标题】:Supersized - Read a specific value from a multilevel array in PHPSupersized - 从 PHP 中的多级数组中读取特定值
【发布时间】:2013-12-06 08:20:34
【问题描述】:

我有一个从文件夹中读取图片的 JavaScript 幻灯片,我需要从 .dat 文件中读取每张图片的描述。 这是脚本:

    <?php

    require ('macoola.inc');
    $upload = new images_upload('installations/', 3000000, 'info.dat');
    $photo_list = $upload->read_data(); #this gets unserialized values from info.dat

#read all jpegs in the folder
    $path_userspecific_array = explode(";", $_SESSION['userDirs']);
    $images_splice = null;
    settype($images_splice, "array");
    foreach($path_userspecific_array as $thisdir){ 
    $thispath = ('installations/' . $thisdir);
    $thisimages = null;
    $thisimages = glob($thispath.'/{*.jpg,*.JPG,*.jpeg,*.JPEG}', GLOB_BRACE);
    $images_splice = array_merge($images_splice, $thisimages);
    }
    ?>

然后这里是java:

 {
    image: '<?php
    echo $filename ?>',
    title: '<?php   
    **#show description here**
    ?>',
thumb : '<?php                                                                      echo $filename                                                                          ?>'
                                                                 }

提前谢谢你。

【问题讨论】:

    标签: javascript php arrays slideshow


    【解决方案1】:

    我终于解决了这个问题!解决方案非常简单。 我没有使用另一个脚本来读取文件夹中的图像,而是直接从 .dat 文件中提取了图片和描述的链接,如下面的代码所示:

    <?php
    
    require ('macoola.inc');
    $upload = new images_upload('url/', 3000000, 'info.dat');
    $photo_list = $upload->read_data();
    $photo_url = "url/";
    
    ?>
    

    然后使用 foreach 函数打印我需要的字符串以放入 Supersized 的“幻灯片”字段中:

    <?php                                            
    foreach ($photo_list as $key=>$val){
    $input .= " image: '".$photo_url.$key."', title: '".$val['desc']."', thumb : '',";
    ?> 
                                                            { <?php echo $input; ?> },
    <?php } ?>  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-12
      • 2015-02-15
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 2018-01-01
      相关资源
      最近更新 更多