Currently I am running this for loop which generates some content
$total = count($_FILES['uploaded_file']['name']);
$str="";
for($i=0; $i<$total; $i++)
{
$content="";
$str=$str."";
$file_path = "v/";
$tmpFilePath = $_FILES['uploaded_file']['tmp_name'][$i];
$ogfilename = $_FILES['uploaded_file']['name'][$i];
$ogfilesize = $_FILES['uploaded_file']['size'][$i];
$filename=$_FILES['uploaded_file']['name'][$i];
$str=$str.'<div style="border-bottom: 1px solid #eee; padding-bottom: 10px;">Song Name: '.$ogfilename.' <br>URL: <a href="http://traxchive.com/v/'.$rand.'">v/'.$rand.'</a><br>File Name: '.$filename.'<br>Size: '.$val.'</div>';
}
$str=$str."";
echo $str;
print '<textarea style="width: 100%"><a href="/v/'.$rand.'">'.$ogfilename.'</a></textarea>';
I'm trying to make it so that all of the results which are returned within the for loop will be displayed inside of a <textarea>
tag as you can see being declared at the bottom. (this only returns the last result how ever if numerous files are uploaded)
How can I make it so that all of the results will return in the <textarea>
portion?
Thats because $ogfilename
get overridden every time the loop ran. You need to make the $ogfilename
variable the same as $str
, that way it collect a list of in a string format.
$total = count($_FILES['uploaded_file']['name']);
$str="";
$cont = "";
for($i=0; $i<$total; $i++)
{
$content="";
$str=$str."";
$file_path = "v/";
$tmpFilePath = $_FILES['uploaded_file']['tmp_name'][$i];
$ogfilename = $_FILES['uploaded_file']['name'][$i];
$ogfilesize = $_FILES['uploaded_file']['size'][$i];
$filename=$_FILES['uploaded_file']['name'][$i];
$cont=$cont.'<a href="/v/'.$rand.'">'.$ogfilename.'</a>';
$str=$str.'<div style="border-bottom: 1px solid #eee; padding-bottom: 10px;">Song Name: '.$ogfilename.' <br>URL: <a href="http://traxchive.com/v/'.$rand.'">v/'.$rand.'</a><br>File Name: '.$filename.'<br>Size: '.$val.'</div>';
}
$str=$str."";
echo $str;
print '<textarea style="width: 100%">'.$cont.'</textarea>';
In this case its lot easier to make a list of strings that are links
</div>
In your loop where you set the file name, instead of overwriting the vairable you can concatenate instead,
Change,
$ogfilename = $_FILES['uploaded_file']['name'][$i];
To,
$ogfilename .= $_FILES['uploaded_file']['name'][$i] . ' ';
This can be done with any string variable where you require it to add on to instead of overwriting.
Reading Material
Try Something like below:
$total = count($_FILES['uploaded_file']['name']);
$str="";
$textareacontent = "";
for($i=0; $i<$total; $i++)
{
$content="";
$str=$str."";
$file_path = "v/";
$tmpFilePath = $_FILES['uploaded_file']['tmp_name'][$i];
$ogfilename = $_FILES['uploaded_file']['name'][$i];
$ogfilesize = $_FILES['uploaded_file']['size'][$i];
$filename=$_FILES['uploaded_file']['name'][$i];
$str=$str.'<div style="border-bottom: 1px solid #eee; padding-bottom: 10px;">Song Name: '.$ogfilename.' <br>URL: <a href="http://traxchive.com/v/'.$rand.'">v/'.$rand.'</a><br>File Name: '.$filename.'<br>Size: '.$val.'</div>';
$textareacontent .= '<a href="/v/'.$rand.'">'.$ogfilename.'</a> ';
}
$str=$str."";
echo $str;
print '<textarea style="width: 100%">'.$textareacontent.'</textarea>';