我有一个表单,如何将其一一插入数据库。例如:-
<form method="post">
<input type="file" name="img[]">
<input type="file" name="img[]">
<input type="file" name="img[]">
</form>
最佳答案
if(isset($_POST['submit'])){
if(count($_FILES['img']['name']) > 0){
//Loop through each file
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if($tmpFilePath != ""){
//save the filename
$shortname = $_FILES['upload']['name'][$i];
//save the url and the file
$filePath = "uploaded/" . date('d-m-Y-H-i-s').'-'.$_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $filePath)) {
$files[] = $shortname;
//insert into db
//use $shortname for the filename
//use $filePath for the relative url to the file
}
}
}
}
这可能对你有帮助
关于php - 如何用数组上传多张图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52744982/