SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's my lil code snipet

    Code:
    $fd=fopen($partydir, "r");
    $imagelist=fread($fd, filesize($partydir));
    fclose($fd); 
    for($t=0;$t<=30;$t++) {
    echo($imagelist[$t] . "<br>");
    }
    $partydir is the url of a txt file with a listing of all the pictures in the directory.

    i want to get that list into an array.

    this part,

    Code:
    for($t=0;$t<=30;$t++) {
    echo($imagelist[$t] . "<br>");
    }
    is testing $imagelist and nothing is in it.

    can someone help me out? the php manual on php.net doesn't really cover teh fopen, fread and fclose functions very well.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nordan,

    A couple of things, how is the text file formatted let's take to possibilites one it looks like

    image1.gif image2.gif image3.gif image4.gif

    To get this into an array one would do
    PHP Code:
    $file file("yourfile");
    foreach(
    $file as $val) {
    $tmp explode(" "$val);
    for(
    $i=0;$i<count($tmp);$i++) {
    $imagelist[] = $tmp[$i];
    }

    if they are like this

    image1.gif,image2.gif,image3.gif,image4.gif

    Then
    PHP Code:
    $file file("yourfile");
    foreach(
    $file as $val) {
    $tmp explode(","$val);
    for(
    $i=0;$i<count($tmp);$i++) {
    $imagelist[] = $tmp[$i];
    }

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if this would be more efficient than freddy's method but it is shorter.

    image1.gif,image2.gif,image3.gif,image4.gif,
    image5.gif,image6.gif,image7.gif,image8.gif,
    PHP Code:
    <?
    $file 
    implode("\\n",file('http://..../file.txt'));
    $images explode(",",$file); //now contains the images
    ?>
    For some reason the newline is turning out to be just
    "n" rather than "\ n" (without the space).


    By the looks of your code snippet though, it seems as though there is one image per line. In that case
    $images = file("http://............/file.txt");
    will return all the contents of the file into an array, where each line is one element.
    Last edited by jrap; Feb 17, 2001 at 21:11.

  4. #4
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx robp. you were right about the txt file format being one image per line. worked out great

    for the directory i'm testing it on (it'll be easy to implement the rest of the picture directories in once i'm done) the directory contains 91 pictures. i've got it setup to display 20 pictures per page.
    here's my code snipit for that part

    Code:
    $NrOfPics=count($imagelist); 
    $NrOfPages=ceil($NrOfPics/20); 
    
    $limit= 20;
    $FirstPic=(($PageNr-1)*$limit)+1;  
    $LastPic=($PageNr)*$limit; 
    
    echo("<center>");
    for($p=$FirstPic; $p<=$LastPic; $p++) {
    	echo("<img src=$partydir$imagelist[$p]><br>&nbsp<br>");
    	}
    echo("</center><br>&nbsp<br>");
    
    for($i=1;$i<=$NrOfPages;$i++) { 
    	echo ("<a href=$PHP_SELF?partyid=$partyid&PageNr=$i>Page $i</a>-"); 
    	}
    its pretty crude as in how in the format that it displays the pictures right now but i'll work on beautifying it once its done. what i'm wondering is this...
    how do i test to find out the last picture?
    on the 5th page it should only show 11 pictures but instead it shows 11 pictures and 9 dead links. how do i prevent that?

    someone suggested to me
    Code:
    $LastPic=($LastPic>$NrOfPics)?$LastPic:$NrOfPics;
    but i have NO idea what that does and everytime i put it into my code it works.. but it also creates the problem that ALLL the pics are displayed on the first page.. then from the 21'st pic to the last one are displayed on the second, then the 41'st to the last are displayed on the 3rd, etc.. ect..

  5. #5
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, figured it out on my own

    guess i shouldn't jump to asking for help on these boards so quickly.

    hehe

    thanx again for the help freddydoesphp and robp. that one problem wuz adoozer for me. i wuz looking at it and trying to figure it out for the past couple dayz. thanx!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •