spilling my beans
Posted: Fri Apr 25, 2003 10:18 pm
after about two or three hours of frustration, i've decided i'm just going to post my code and see if anyone can help me out. hopefully most of you can see past my amateur coding and really figure out what the root of the problem is. my aim is to get the text from $file, a text file, into a string, and eventually, into a text area.
As stated in the comments, I know that $TheFile is set wrong, and I"m hoping someone can help me out. I believe that's the ONLY thing keeping this script from working. The form is put out correctly, with the right number of boxes, so this works fine. The first function detecting the number of "totalXXX.txt" files works fine. the function putting out the text area works fine. the only thing that doesn't seem to work fine is the process of getting the text INTO the text area, which eventually traces back to the fact that fopen can't open the file because it can't seem to find it. (permissions are all already set on it).
I hope someone can help me out. Thanks.
-ben
Code: Select all
<?php
//error_reporting(E_ALL);
$PageTitle="{$_GET[DirName]} File Settings";
$HeaderTitle="{$_GET[DirName]} File Settings.";
$Current = getcwd();
require("header.php");
//This function takes text from the text file and outputs it. The root of my problems lie in what $TheFile should be, but isn't.
function FillTextArea($TheFile, $DirectoryName){
$ThePath = "/directories/" . "$DirectoryName/" . "$TheFile";
$Open = fopen($TheFile, "r");
if ($Open){
print("Sucess");
$Data = implode('', file("$ThePath"));
print($Data);
fclose($Open);
} else {
print("Not working");
}
}
//Here I'm just making it easy to get it into a print() function
$FTA = FillTextArea();
//Beginning the form
print ("<form name="MasterForm" method="POST" action="HandleForm.php">");
//Here we go. DirName was passed through a get function, it all depends on what the user chose for a directory.
$DirName = $_GET['DirName'];
$PictureArray = array();
$DescArray = array();
if ($handle = opendir("./directories/$DirName")) {
while (false !== ($file = readdir($handle))) {
//I only want .txt files returned. In retrospect, I didn't need to add the first two statements.
if ($file != "." && $file != ".." && eregi(".+\.txt", $file)) {
//There's two types of text files. Example: totalBuilding.txt and just Building.txt. Below tests the former.
if (eregi("total", $file)){
//Just counting the number of text files to have a preset number when the text input loads.
$PictureArray[] = $file;
$TotalPictures = count($PictureArray);
print("<FONT FACE="Tahoma" SIZE="2">{$file}'s number of pictures: </FONT><input type="text" name="text$file" value="$TotalPictures" size=1><BR>");
} else {
//Obviously, if it's the plain text file, I want a text area made. My hopes are to have the original text from the text file in the text area when it loads.
echo "<FONT FACE="Tahoma" SIZE="2">{$file}'s number of pictures: </FONT><textarea name="textarea$file" cols="40" rows="8">$FTA</textarea><BR>";
}
}
}
closedir($handle);
}
print ("</FORM>");
require("footer.php");
?>I hope someone can help me out. Thanks.
-ben