Hi all,
I have a question about the code.
I am working on this code to let others to upload their text files in the same format. (having category name and display the answer after : (colon)..
So, I am trying to let people to be able to upload their text file and go through the code that filters (parses) out the contents I want (what I want is showing the contents after the colon..) Can anyone please help me out?
I have a question about the code.
I am working on this code to let others to upload their text files in the same format. (having category name and display the answer after : (colon)..
So, I am trying to let people to be able to upload their text file and go through the code that filters (parses) out the contents I want (what I want is showing the contents after the colon..) Can anyone please help me out?
Code:
<?php
$fileName = $_FILES['fileHandle']['name'];
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
"C:/upload/" . $_FILES["fileToUpload"]["name"]);
if ($_FILES["fileToUpload"]["error"] > 0)
{
echo "Apologies, an error has occurred.";
echo "Error Code: " . $_FILES["fileToUpload"]["error"];
}
else
{
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
"C:/upload/" . $_FILES["fileToUpload"]["name"]);
}
// $file = fopen($fileName, "r") or exit ("Unable to open file!");
//starting here to parse out the contents of the file..
while(!feof($file))
$line = fgets($file); // Read a line.
//escape if the line is empty
if (trim($line) == "")
continue;
//explode from the :
$fields = explode(":", $line, 2);
echo "<b>$fields[0]</b>";
//checks if second part exists
if (isset($fields[1]))
echo " : $fields[1]";
echo "<br/>";
}
fclose($file);
?>
Comment