Что касается вашего второго вопроса, то, что было бы более разумным, чтобы вставить рекламу затем вставить все картинки.
Для вашего первого вопроса,
HTML-код будет что-то вроде этого
<form name="multiupload" action="uploadmany.php" method="post" enctype="multipart/form-data">
<input name="filesToUpload[]" type="file" multiple /></td>
<td collapse=2><input name="savemultiimg" type="submit" value="submit"></td>
</form>
и вот код PHP. переменная $err
- это уведомление о состоянии загрузки.
<?php
require("DataBaseConnection.php");
if(isset($_POST["savemultiimg"])) {
for($i=0;$i<count($_FILES['filesToUpload']['tmp_name']);$i++){
$name=$_FILES['filesToUpload']['name'][$i];
$tmp_name=$_FILES['filesToUpload']['tmp_name'][$i];
$target_dir = "images/"; //the dir where you want to save images
$target_file = $target_dir . rand().'_'.($name); //this will be the name of the img, and we will give it a random number so if you uploaded two image with same name you don't have a problem
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
$check = getimagesize($tmp_name);
if($check !== false) {
//echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
$err= "file you uploaded is not an image";
$uploadOk = 0;
}//end if
// Check if file already exists,, this will appear if you removed the random number on the top
if (file_exists($target_file)) {
$err ="file already exists";
$uploadOk = 0;
}//end if
if ($uploadOk != 0)
{
if (move_uploaded_file($tmp_name, $target_file)) {
$err ="file uploaded succ.";
$sql = "...";//your sql here
$result = $con->query($sql);
} else {
$err ="unecpected error occured";
} //end if upload
}//end ($uploadOk != 0)
}//end forloop
header('Location: index.php?err='.$err.');
}
?>
Этот код является из одного из моих университетских проектов, и я только что его модифицировал, чтобы подшутить над вами. если это вызвало у вас какую-либо ошибку, просто скажите мне, и я буду рад помочь вам.
Исходный код копируется с w3schools, и изменения были сделаны для множественной загрузки.
Я собираюсь попробовать это сейчас, плохо сообщит вам о результатах! –
Надеюсь, он сработает. не может дождаться, чтобы узнать результат. –
Я не могу проверить, работает ли он. страница не показывает ничего с кодом, реализованным на странице. –