这是我提交项目时的代码,他们的数据库有一个双条目,我创建了一个主键自动增量,当我在数据库中上传多个图像时,他们只存储第一个图像,我使用每个函数在数据库中存储多个图像*
HTML
<div class="card">
<div class="card-header">Upload Projects</div>
<div class="card-body">
<form action="../partials/project_upload.php" method="post" enctype="multipart/form-data">
<div class="input-group input-group-sm mb-3">
<label class="col-md-4 col-form-label text-md-right">Catagory Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="catName" required>
</div>
</div>
<div class="input-group input-group-sm mb-3">
<label class="col-md-4 col-form-label text-md-right">Project Details</label>
<div class="col-md-6">
<input type="text" class="form-control" name="proDetails" required>
</div>
</div>
<div class="input-group input-group-sm mb-3">
<label class="col-md-4 col-form-label text-md-right">Project info</label>
<div class="col-md-6">
<input type="text" class="form-control" name="proDate"
placeholder="Date of Project" required>
<input type="text" class="form-control mt-3" name="proLocation"
placeholder="Project Locaiton" required>
</div>
</div>
<div class="form-group row">
<label class="col-md-4 col-form-label text-md-right">Project Frist Image
Select</label>
<div class="col-md-6">
<input type="file" class="form-control" name="image[]" autofocus>
</div>
</div>
<div class="form-group row">
<label class="col-md-4 col-form-label text-md-right">Project Second Image
Select</label>
<div class="col-md-6">
<input type="file" class="form-control" name="image[]" autofocus>
</div>
</div>
<div class="form-group row">
<label class="col-md-4 col-form-label text-md-right">Project Third Image
Select</label>
<div class="col-md-6">
<input type="file" class="form-control" name="image[]" autofocus>
</div>
</div>
<div class="form-group row">
<label class="col-md-4 col-form-label text-md-right">Project Fourth Image
Select</label>
<div class="col-md-6">
<input type="file" class="form-control" name="image[]" autofocus>
</div>
</div>
<div class="form-group row">
<label class="col-md-4 col-form-label text-md-right">Project Fifth Image
Select</label>
<div class="col-md-6">
<input type="file" class="form-control" name="image[]" autofocus>
</div>
</div>
<div class="col-md-6 offset-md-4">
<button type="submit" name="submit" class="btn btn-info">
Upload
</button>
</div>
</div>
</form>
</div>
PHP****php在此处上传项目代码
include("../database/db_connect.php");
if (isset($_POST['submit'])) {
// Insert the data to the database
$catName=$_POST['catName'];
$proDetails=$_POST['proDetails'];
$proDate=$_POST['proDate'];
$proLocation=$_POST['proLocation'];
//all image store in database
$extension= array('jpeg','jpg','png',);
foreach ($_FILES['image']['tmp_name'] as $key => $value) {
$filename=$_FILES['image']['name'][$key];
$filename_tmp=$_FILES['image']['tmp_name'][$key];
$ext=pathinfo($filename,PATHINFO_EXTENSION);
if(in_array($ext,$extension))
{
if(!file_exists('../assets/projects/'.$filename))
{
move_uploaded_file($filename_tmp, '../assets/projects/'.$filename);
}
}
}
$sql="INSERT INTO `projects` (`cat_name`, `pro_details`, `pro_date`, `pro_location`,`pro_image_frist`,`pro_image_second`,`pro_image_third`,`pro_image_fourth`,`pro_image_fifth`) VALUES ('$catName', '$proDetails', '$proDate', '$proLocation','$filename','$filename','$filename','$filename','$filename')";
mysqli_query($conn,$sql);
if (mysqli_query($conn,$sql) == true) {
echo "Project Inserted successfully!";
$_SESSION["access"] = 1;
}else{
echo "Project Inserted not successfully!";
$_SESSION["access"] = 1;
}
header('Location: admin.php');
}
数据库
SQL语句
--
-- Table structure for table `projects`
--
CREATE TABLE `projects` (
`cat_id` int(11) NOT NULL,
`cat_name` varchar(15) NOT NULL,
`pro_details` varchar(1000) NOT NULL,
`pro_date` varchar(15) NOT NULL,
`pro_location` varchar(255) NOT NULL,
`pro_image_frist` varchar(255) NOT NULL,
`pro_image_second` varchar(255) NOT NULL,
`pro_image_third` varchar(255) NOT NULL,
`pro_image_fourth` varchar(255) NOT NULL,
`pro_image_fifth` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `projects`
--
INSERT INTO `projects` (`cat_id`, `cat_name`, `pro_details`, `pro_date`, `pro_location`, `pro_image_frist`, `pro_image_second`, `pro_image_third`, `pro_image_fourth`, `pro_image_fifth`) VALUES
(51, 'architecture', 'akbuilder is a great agency for building design', '5/05/2022', 'Sunamganj, ibrahimpur', '35.jpg', '35.jpg', '35.jpg', '35.jpg', '35.jpg'),
(52, 'architecture', 'akbuilder is a great agency for building design', '5/05/2022', 'Sunamganj, ibrahimpur', '35.jpg', '35.jpg', '35.jpg', '35.jpg', '35.jpg'),
(53, 'Design', 'hello this is project details', '12/05/2027', 'London', '46.jpg', '46.jpg', '46.jpg', '46.jpg', '46.jpg'),
(54, 'Design', 'hello this is project details', '12/05/2027', 'London', '46.jpg', '46.jpg', '46.jpg', '46.jpg', '46.jpg'),
(55, 'architecture', 'akbuilder is a great agency for building design', '12/05/2030', 'Sunamganj, sylhet', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg'),
(56, 'architecture', 'akbuilder is a great agency for building design', '12/05/2030', 'Sunamganj, sylhet', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg'),
(57, 'Akbuilders', 'A paragraph is a self-contained unit of discourse in writing dealing with a particular point or idea. A paragraph consists of one or more sentences. Though not required by the syntax of any language, paragraphs are usually an expected part of formal writing, used to organize longer prose', '2020', 'america', '11.jpg', '11.jpg', '11.jpg', '11.jpg', '11.jpg'),
(58, 'Akbuilders', 'A paragraph is a self-contained unit of discourse in writing dealing with a particular point or idea. A paragraph consists of one or more sentences. Though not required by the syntax of any language, paragraphs are usually an expected part of formal writing, used to organize longer prose', '2020', 'america', '11.jpg', '11.jpg', '11.jpg', '11.jpg', '11.jpg'),
(59, '3D', 'hello this is project details', '12/05/2027', 'London', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg'),
(60, '3D', 'hello this is project details', '12/05/2027', 'London', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg'),
(61, 'projects', 'building design agency ', '2029', 'Sylhet', 'item1.jpg', 'item1.jpg', 'item1.jpg', 'item1.jpg', 'item1.jpg'),
(62, 'projects', 'building design agency ', '2029', 'Sylhet', 'item1.jpg', 'item1.jpg', 'item1.jpg', 'item1.jpg', 'item1.jpg');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `projects`
--
ALTER TABLE `projects`
ADD PRIMARY KEY (`cat_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `projects`
--
ALTER TABLE `projects`
MODIFY `cat_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=63;
COMMIT;
1条答案
按热度按时间ukqbszuj1#
您可以为不同的输入尝试不同的名称。(请使用'image1'、'image2'和' image3',而不要使用image[])