Hello -
I'm trying to open a flat text data file. In it I have a list of image files names & words (example test1.jpg, test, test2.jpg, ect). I want to detect which is which and then have a action happen. This is what I have so far -
<?php
$TheFile = "data3.txt";
$Open = fopen ($TheFile, "r");
if ($Open) {
print ("URLs currently listed in the data file:<P>\n");
$Data = file ($TheFile);
for ($n = 0; $n < count($Data); $n++) {
$GetLine = explode("\t", $Data[$n]);
print ("$GetLine[0]<BR>\n$GetLine[1]<P>\n");
}
fclose ($Open);
print ("<HR><P>\n");
}
$filename = "$GetLine";
$extention = GetFileExtention($filename);
echo $extention;
//
function GetFileExtention($filename) {
$ext = explode(".", $filename);
$extention = "";
for($i=1;$i<=sizeof($ext)-1;$i++) {
if($ext) {
$extention .= ".".$ext[$i];
}
}
return $extention;
}
?>
PHP Code Help Please
Moderator: General Moderators
-
maxheadroom
- Forum Newbie
- Posts: 2
- Joined: Tue Dec 23, 2003 9:20 pm
Ok, in that case the following may work...
$imageList will end up being an array full of the images.
To get the name and extension of any of the images you simply do something like... echo $imageList[3]->extension
Hope that helps.
Code: Select all
<?php
$file = "theFile.txt";
ob_start();
require($file);
$contents = trim(ob_get_contents());
ob_end_clean();
$images = explode(",", $contents);
foreach($images as $key => $value)
{
$bits = explode(".", $value);
$imageList[$key]->name = $value;
$imageList[$key]->extension = $bits(count($bits)-1);
}
// This next bit simply displays the contents on screen.
foreach($imageList as $object)
{
echo "Filename: ".$object->name."<br />";
echo "Extension: ".$object->extension."<hr />";
}
?>To get the name and extension of any of the images you simply do something like... echo $imageList[3]->extension
Hope that helps.