I entered the image files into the database through the input form. The database contains elements of name, hash, and time. When I upload multiple files, only 'Array' is outputted to the name. I have to show the images on the view page. I want to store elements of the array separately when storing them in a database, or to output elements of the array separately when outputting them. Please help me
upfile.php :
<form action="upload.php" method="post" enctype="multipart/form-data">
<input name="upload[]" type="file" multiple="multiple" />
<input type="submit">
</form>
upload.php :
if(!$_FILES['upload']['name'])
{
echo "<script>alert('Emtpty');";
echo "history.back();</script>";
exit;
}
if(strlen($_FILES['upload']['name']) > 255)
{
echo "<script>alert('Too long');";
echo "history.back();</script>";
exit;
}
$date = date("YmdHis", time());
$dir = "./dir";
$file_hash = $date.$_FILES['upload']['name'];
$file_hash = md5($file_hash);
$upfile = $dir.$file_hash;
$total = count($_FILES['upload']['name']);
for($i=0; $i<$total; $i++) {
if(is_uploaded_file($_FILES['upload']['tmp_name'])) {
if(!move_uploaded_file($_FILES['upload']['tmp_name'], $upfile))
{
echo "upload error";
exit;
}
}
}
@ $db = new mysqli('localhost', 'DBid', 'Password', 'DBname');
if(mysqli_connect_errno())
{
echo "DB error";
exit;
}
$query = "insert into ftp (name, hash, time)
values('".$_FILES['upload']['name']."',
'".$file_hash."', '".$date."')";
$result = $db->query($query);
if(!$result)
{
echo "DB upload error";
exit;
}
$db->close();
echo "<script>alert('Upload');";
echo("location.href='./view.php';</script>");
If output the name, nothing is generated.
name | hash | time
Array | 6933b06c625e6900e1570298e0e2baf8 | 2019-08-09 01:35:47
Array | cecef12bb58ef31885bd1a0625909269 | 2019-08-09 02:28:51