Jump to content


Photo

Should be Simple


  • Please log in to reply
4 replies to this topic

#1 ShiVer

ShiVer
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationJoMo

Posted 28 April 2006 - 01:58 PM

Alright, I'm making this way to complicated on myself so hopefully someone with a fresh start could help.

Heres the plan:
I have several files in a directory.
I want to open and read the directory to only find text files.
The text files are setup in the following format: picture.jpg|Title of Clip|clip.flv
"foreach" text file I want to explode to an array so I can show it like the following:

HTML>>
-------------
|           | Title of clip
|  picture  |
|           |
-------------

The image and title will be a hyperlink so that when clicked it will open up another text document set by myself and write to it the clip.flv

Note: So basically it's like uploading the information to a database and then using a while loop to pull it out and show all the results. The situation being the way it is I don't have access to a DB so I'm trying to use flatfile.

I know most of you are probably lost now so please ask any questions and I'll do my best to answer! Thanks!

- Ryan

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 28 April 2006 - 02:47 PM

You could try something like this...
<?php
//Loop through all text files in a directory
foreach(glob("path/to/files/*.txt") as $file) {
    $content = file($file);
    //Loop through each line in the file
    foreach($content as $line) {
        //Seperate the line by the pipe symbol into an array and display
        $temp = explode("|",$line);
        echo "<p>Image: $temp[0]<br/>Title: $temp[1]<br/>Flash: $temp[2]</p>";
    }
}
?>


#3 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 28 April 2006 - 02:49 PM

This will get you on your way.

// open only text files in the current directory
foreach (glob("*.txt") as $filename) 
{
echo $filename<br>";
}

wisewood: proven fact, I am both wise, and wooden.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 28 April 2006 - 02:57 PM

This answer assumes that all the text files are named "something.txt"

<?php
foreach(glob(*.txt) as $textfile) {
    $tmp = file($textfile);
    list($pic, $title, $clip) = explode(trim($tmp[0]));
    list($w, $h, $t, $attr) = getimagesize($filename);
    echo '<img src="' . $pic . '" ' . $attr . '><a href="' . $clip . '">' . $title . '</a><br>';
}
?>

Ken

#5 ShiVer

ShiVer
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationJoMo

Posted 28 April 2006 - 03:25 PM

Thank you all, I got SemiApocalyptic's to work but I used kenrbnsn's.

@kenrbnsn: Ya forgot the seperation parameter in explode. lol

Thanks again to all three of ya. I'll be set for the next time I need to do somethin like this as well!

- Ryan




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users