下面的HTML脚本会收集用户信息,文件和帖子到数据库。挑战在于,当文件是多个时,它会将文件路径发送到不同的行。请帮我配置上传文件,将每次上传图片的文件路径发送到一行。谢谢。
HTML
酒店名称* 镇/市* “/> (+)添加文件upload.php的。
<?php
include ("connection.php");
if ($_POST["action"] == "Upload")
die ("Error: no files uploaded!");
$file_count = count($_FILES["item_file"]['name']);
echo $file_count . " file(s) sent... <BR><BR>";
if(count($_FILES["item_file"]['name'])>0) { //check if any file uploaded
for($j=0; $j < count($_FILES["item_file"]['name']); $j++) { //loop the uploaded file array
$filen = $_FILES["item_file"]['name'][$j];
// ingore empty input fields
if ($filen!="")
{
// destination path - you can choose any file name here (e.g. random)
$path = "images/" . $filen;
if(move_uploaded_file($_FILES["item_file"]['tmp_name']["$j"],$path)) {
echo "File# ".($j+1)." ($filen) uploaded successfully!<br>";
} else
{
echo "Errors occoured during file upload!";
}
//create array of temporarily grab variables
$input_arr=array();
//grabs the post variables and adds slashes
foreach($_POST as $key=> $input_arr){
$_POST[$key]=addslashes($input_arr);
}
mysql_select_db("fcom_com") or die("Could not select database");
mysql_query("INSERT INTO contri (field_1,field_2,URL)
VALUES('".$_POST['field_1']."','".$_POST['field_2']."','".$_FILES['item_file']['name']["$j"]."')");
}
}
}
&GT;