我正在使用PHP和Mysqli创建图库网站,我有一个图像上传器屏幕,可以选择多个图像,标题项目等。创建新目录的代码是什么(在“images / projects /”中) )在服务器上的项目名称的名称?这样所有选定的文件都保存到名为“imageTitle”字段的新文件夹中。
HTML:
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="image">Select a file:</label>
<input type="file" name="image[]" id="image" multiple />
<br /><br>
<label for="picname">Title:</label>
<input type="text" name="picname" id="picname" />
<br /><br>
<label for="picdesc">Description:</label>
<input type="text" name="picdesc" id="picdesc" />
<br /><br>
<label for="piccat">Category:</label>
<select name="piccat" id="piccat">
<option value="--"></option>
<option value="animation">Animation</option>
<option value="illustration">Illustration</option>
<option value="photography">Photography</option>
</select>
<br /><br>
<input type="submit" name="submit" value="Submit" />
</form>
PHP:
<?php
$path = "images/projects/";
include("check.php");
if (isset($_POST["submit"])) {
for ($i = 0; $i < count($_FILES["image"]["name"]); $i++) {
$image = $_FILES["image"]["tmp_name"][$i];
$imageName = $_FILES["image"]["name"][$i];
$imageSize = $_FILES["image"]["size"][$i];
$imageType = $_FILES["image"]["type"][$i];
$imageTitle = $_POST["picname"];
$imageDescription = $_POST["picdesc"];
$imageCategory = $_POST["piccat"];
$path = $path . $imageName;
$imageFileType = pathinfo($path,PATHINFO_EXTENSION);
$query = $db -> prepare("INSERT INTO images
(user_id, image, description, type, title, size, category)
VALUES (?, ?, ?, ?, ?, ?, ?)");
$query -> bind_param('issssis', $_SESSION['user_id'],
$imageName, $imageDescription, $imageType,
$imageTitle, $imageSize, $imageCategory);
$query -> execute();
$query -> close();
if($imageFileType != "jpg" && $imageFileType != "png"
&& $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "mp4") {
echo "Sorry, only JPG, JPEG, PNG, MP4 & GIF files are allowed.";
}
if ($imageName){
move_uploaded_file($image, $path);
}
}
}
?>