我知道这里有类似的问题,但我的问题是我没有看到有答案的我,我希望用户在一个帖子上传多张照片,所以我的问题是我必须添加更多行到我的数据库来存储每个文件名,如果是这样,如果我有10行,用户希望上传11张照片会发生什么,我只是想知道facebook如何做到这一点
if(count($_FILES['uploads']['filesToUpload'])) {
foreach ($_FILES['uploads']['filesToUpload'] as $file) {
//do your upload stuff here
echo $file;
}
}
我可以上传多张照片并移至文件夹,但如何将所有名称存储在我的数据库中
答案 0 :(得分:2)
因此,如果我理解正确,您只需要获取当前登录用户的id
,然后拥有一个photos
表,其中至少包含一个照片和用户的ID作为外键。这样,您就可以根据需要为单个用户添加任意数量的照片。
答案 1 :(得分:1)
答案 2 :(得分:0)
这是一个例子,你只需自己调整它。
<form action="file_reciever.php" enctype="multipart/form-data" method="post">
<input type="file" name="files[]" multiple/>
<input type="submit" name="submission" value="Upload"/>
</form>
PHP go(file_reciever.php):
<?php
if (isset($_POST['submission'] && $_POST['submission'] != null) {
for ($i = 0; $i < count($_FILES['files']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['files']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != "") {
//Setup our new file path
$newFilePath = "./uploadFiles/" . $_FILES['files']['name'][$i];
//Upload the file into the temp dir
if (move_uploaded_file($tmpFilePath, $newFilePath)) {
//Handle other code here
}
}
}
}
?>
我希望它有所帮助。