jQuery pull images from directory

后端 未结 4 2040
再見小時候
再見小時候 2020-12-03 05:51

Is it possible to pull a bunch of .jpg pictures form a local file and throw them into a list? Sorry, I was very vague

Pulling from a directory (relitive to

相关标签:
4条回答
  • 2020-12-03 06:21

    Are you saying you have a local text file filled with the locations of images?

    <?php
    $handle = fopen("localfile.txt", 'r');
    
    echo '<ul>';
    while ($line = gets($handle)) {
        echo '<li><img src="' . $line . '"/></li>';
    }
    echo '</ul>';
    
    fclose($handle);
    ?>
    
    0 讨论(0)
  • 2020-12-03 06:21

    Short answer: No, you cannot.

    Long answer: You're going to need to create a list of those files with php with the code similar to what Charles posted, then AJAX that into your jQuery.

    0 讨论(0)
  • 2020-12-03 06:21

    Using php code to print all images of a directory:

    <?php
    $a=array();
    if ($handle = opendir('.')) {
        while (false !== ($file = readdir($handle))) {
           if(preg_match("/\.png$/", $file)) 
                $a[]=$file;
        else if(preg_match("/\.jpg$/", $file)) 
                $a[]=$file;
        else if(preg_match("/\.jpeg$/", $file)) 
                $a[]=$file;
    
        }
        closedir($handle);
    }
    
    foreach($a as $i){
        echo "<img src='".$i."' />";
    }
    ?>
    
    0 讨论(0)
  • 2020-12-03 06:33

    You could use the following to dynamically create an image and append it to a list.

    $('<img />')
        .attr('src', 'FOLDER LOCATION HERE')
        .appendTo('#mylist')
    

    some quick searching led me to find a FileSystemObject ( ActiveX =( ) to search a folder for files.

    here is a link: http://www.codeproject.com/KB/scripting/search_in_files.aspx

    but if you are doing any server side processing (.net, php, whatever) that would be the best way to figure out what images are available to you to display on the page. (so if you could clarify)

    0 讨论(0)
提交回复
热议问题