我正在尝试创建一个上传文件(在这种情况下是视频)的PHP网站并显示它们。我正在尝试将它们存储在一个数组中,然后在页面上显示它们。问题是,页面仅显示上传的最后一个视频,即该数组仅存储上次上传的文件。我怎样才能使数组存储$array[0]
中的第一个上传文件,$array[1]
中的第二个,依此类推......然后显示它们?
这是我的代码(HTML表单)
<form action="upload.php" method="POST" enctype="multipart/form-data">
<p>Video to Upload: <br> <input type="file" name="video" /></p>
<p><input type="submit" name="Submit" value="Submit" /></p></form>
PHP代码(upload.php
)
<?php
$videoname = $_FILES["video"]["name"];
$tmp_name = $_FILES["video"]["tmp_name"];
$thevideos = array();
if (isset($videoname))
{
if (!empty($videoname))
{
$location = 'uploaded/';
move_uploaded_file($tmp_name, $location.$videoname);
$thevideos[] = $videoname; // the array is only storing $videoname in $the videos[0]??
for ($i = 0; $i <= count($thevideos); $i++)
{
echo "<video width=\"320\" height=\"240\" controls>
<source src=\"/uploaded/" .$thevideos[$i]. "\">
</video> <br>";
}
}
else
{
echo "Please choose a file.";
}
}
?>