I have a simple HTML form that allows a user to select multiple text files. I want to loop through them and echo each one. I have the following code:
Upload text document: <br/><br>
<form action="output.php" method="post" enctype="multipart/form-data">
<input type="file" name="documents[]" size="50" multiple="multiple" />
<br />
<input type="submit" value="Upload File" />
</form>
Then in output.php when I want to echo through each file and echo its contents. I tried this code:
$filenames = array();
if(isset($_FILES["documents"]))
{
for($i=0; $_FILES['documents']['name'][$i] != '' ; $i++)
{
$filenames[$i] = $_FILES['documents']['name'][$i];
$myfile = fopen("$_FILES['documents']['name'][$i]", "r") or die("Unable to open file!");
echo fread($myfile,filesize("$_FILES['documents']['name'][$i]"));
fclose($myfile);
}
}
I get the following error:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\php_sandbox\ValenceV1\ValenceV1_output.php
How can I fix this code, or if there is a better way to do this please do provide it. Thanks.
"$_FILES['documents']['name'][$i]"it doesn't make sense having that