12

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 the index) like.

I want to list them in an image tag, sequentially.

Kevin Brown
  • 12,602
  • 34
  • 95
  • 155
  • Yeah sure. No serioulsy, please clarify your question. Should the images be uploaded? What should the list be? – Pim Jager May 13 '09 at 22:27
  • local as in "get images from c:\MyPrivatePictures"? nope. – Mauricio Scheffer May 13 '09 at 22:28
  • 4
    Do you mean pull files from the client's local computer? I sure hope not. I don't want javascript to access my files. Do you mean pull files from a directory on the server? It can't be done with javascript (and jQuery is javascript), because javascript is run on the client. What you possibly could do is have a server-side script/page/whateveryouuseinyourapplication that returns a list of image url:s, and call it with AJAX, for example using jQuery. – Tomas Aschan May 13 '09 at 22:29
  • That sounds good, how would I do that? – Kevin Brown May 13 '09 at 22:45
  • I think you can find solution [here][1]. [1]: http://stackoverflow.com/questions/8031951/getting-images-from-folder-with-for-jquery-slideshow – Tpojka Mar 16 '13 at 01:19
  • **Get images from folder**: http://stackoverflow.com/a/32940532/383904 – Roko C. Buljan Jan 12 '16 at 12:32

4 Answers4

13

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)

Jon Erickson
  • 112,242
  • 44
  • 136
  • 174
1

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);
?>
Charles
  • 539
  • 1
  • 3
  • 11
0

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.

helloandre
  • 10,541
  • 8
  • 47
  • 64
  • Actually, it is entirely possible with jQuery Ajax independently. I am working on a jQuery plugin that does exactly this, which is intended for galleries, etc. However, I can not reference said project because i'm still working on it. – Studocwho Aug 14 '17 at 23:07
-3

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."' />";
}
?>
L84
  • 45,514
  • 58
  • 177
  • 257
nGinX
  • 1
  • 1