홈>
웹 페이지에 둘 이상의 사진을 추가하려고하는데 1 개만 추가 할 수 있습니다. 웹 페이지에 3 개 이상의 이미지를 추가하려고하는데 파일을 선택할 수있는 버튼을 추가하면됩니다. 하지만 1 개 이상의 파일과 최소 4 개의 사진을 업로드하고 싶습니다. 코드는 다음과 같습니다.
<section class="left">
<ul>
<li><a href="manufacturers.php">Manufacturers</a></li>
<li><a href="bikes.php">Bikes</a></li>
</ul>
</section>
<section class="right">
<?php
if (isset($_POST['submit'])) {
$stmt = $pdo->prepare('INSERT INTO bikes (model, description, price, manufacturerId)
VALUES (:model, :description, :price, :manufacturerId)');
$criteria = [
'model' => $_POST['model'],
'description' => $_POST['description'],
'price' => $_POST['price'],
'manufacturerId' => $_POST['manufacturerId']
];
$stmt->execute($criteria);
if ($_FILES['image']['error'] == 0) {
$fileName = $pdo->lastInsertId() . '.jpg';
move_uploaded_file($_FILES['image']['tmp_name'], '../images/bikes/' . $fileName);
}
echo 'Bike added';
}
else {
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
?>
<h2>Add Product</h2>
<form action="addbike.php" method="POST" enctype="multipart/form-data">
<label>Bike Model</label>
<input type="text" name="model" />
<label>Description</label>
<textarea name="description"></textarea>
<label>Condition</label>
<input type="text" name="Condition" />
<label>Price</label>
<input type="text" name="price" />
<label>Category</label>
<select name="manufacturerId">
<?php
$stmt = $pdo->prepare('SELECT * FROM manufacturers');
$stmt->execute();
foreach ($stmt as $row) {
echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
}
?>
</select>
<label>Bike image</label>
<input type="file" name="image" />
<input type="submit" name="submit" value="Add Product" />
</form>
<?php
}
else {
?>
<h2>Log in</h2>
<form action="index.php" method="post">
<label>Username</label>
<input type="text" name="username" />
<label>Password</label>
<input type="password" name="password" />
<input type="submit" name="submit" value="Log In" />
</form>
<?php
}
}
?>
- 답변 # 1
- 답변 # 2
한 번에 여러 파일을 선택할 수 있지만 여러 개를 추가해야합니다. 그런 다음 이와 같은 파일을 선택할 수 있습니다.
The multiple attribute of the input tag is not supported in Internet Explorer 9 and earlier versions.
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="upload.php" method="post" multipart="" enctype="multipart/form-data"> <input type="file" name="img[]" multiple> <input type="submit"> </form> </body> </html> <?php echo '<pre>'; $img = $_FILES['img']; if(!empty($img)) { $img_desc = reArrayFiles($img); print_r($img_desc); foreach($img_desc as $val) { $newname = date('YmdHis',time()).mt_rand().'.jpg'; move_uploaded_file($val['tmp_name'],'./uploads/'.$newname); } } function reArrayFiles($file) { $file_ary = array(); $file_count = count($file['name']); $file_key = array_keys($file); for($i=0;$i<$file_count;$i++) { foreach($file_key as $val) { $file_ary[$i][$val] = $file[$val][$i]; } } return $file_ary; }
트렌드
- OpenCv의 폴더에서 여러 이미지 읽기 (python)
- 파이썬 셀레늄 모든 "href"속성 가져 오기
- html - 자바 스크립트 - 클릭 후 변경 버튼 텍스트 변경
- git commit - 자식 - 로컬 커밋 된 파일에 대한 변경을 취소하는 방법
- JSP에 대한 클래스를 컴파일 할 수 없습니다
- javascript - 현재 URL에서 특정 div 만 새로 고침/새로 고침
- jquery - JavaScript로 현재 세션 값을 얻으시겠습니까?
- javascript - swiperjs에서 정지, 재생 버튼 추가
- JavaScript 변수를 HTML div에 '출력'하는 방법
- python - 문자열에서 특정 문자 제거
multiple
를 허용하려면 입력 파일에서 파일 선택은 다음과 같습니다선택한 모든 파일을 가져 오려면
와이즈 비즈