Jump to content

Archived

This topic is now archived and is closed to further replies.

ShiVer

Should be Simple

Recommended Posts

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: [b]picture.jpg|Title of Clip|clip.flv[/b]
"[i]foreach[/i]" text file I want to explode to an array so I can show it like the following:

HTML>>
[code]-------------
|           | Title of clip
|  picture  |
|           |
-------------[/code]

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

Share this post


Link to post
Share on other sites
You could try something like this...
[code]<?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>";
    }
}
?>[/code]

Share this post


Link to post
Share on other sites
This will get you on your way.

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

Share this post


Link to post
Share on other sites
This answer assumes that all the text files are named "something.txt"

[code]<?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>';
}
?>[/code]

Ken

Share this post


Link to post
Share on other sites
Thank you all, I got SemiApocalyptic's to work but I used kenrbnsn's.

[b]@kenrbnsn[/b]: 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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.