時,上傳多張圖像不起作用上載限制爲10 MB,但是當我嘗試上載120 KB圖像時,該功能無效。當我上傳一個10 KB的圖像時,它完美地工作,只有當它像100 kB時,它會取消上傳並且根本不起作用。當我嘗試上傳中等分辨率圖像
這是代碼
<body>
<!--Navbar -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">AcquaSpare</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="index.php">Home<span class="sr-only">(current)</span></a></li>
<li><a href="#">Condizioni</a></li>
<li><a href="#">Prodotti</a></li>
<li><a href="#">Ricambi</a></li>
</ul>
<form class="navbar-form navbar-left" method="post" role="search" action="lista_prodotti.php">
<div class="form-group">
<input type="text" name="ricerca" class="form-control" placeholder="Ricerca Prodotto">
</div>
<button type="submit" class="btn btn-default">Invio</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Contattaci</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php
session_start();
require 'config.php';
require 'connect.php';
list($id, $nome, $prezzo, $descrizione, $disponibili, $codice)=mysql_fetch_array(mysql_query("SELECT id AS id, nome, prezzo, descrizione, disponibili, codice FROM prodotti WHERE id='".$_SESSION['prodid']."'"));
if(isset($_SESSION['id'])){
$row = mysql_fetch_assoc(mysql_query("SELECT id AS id, username FROM utenti WHERE id='".$_SESSION['id']."'"));
echo 'Benvenuto, <strong>',$row['username'],'</strong>';
}else{
echo 'Il Mio Account';
}
?><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Carrello</a></li>
<li><a href="#"><i class="fa fa-user" aria-hidden="true"></i> Profilo</a></li>
<li role="separator" class="divider"></li>
<?php
if(isset($_SESSION['id'])){
echo '<li><a href="close_session.php"><i class="fa fa-sign-out" aria-hidden="true"></i> Logout</a></li>';
}else{
echo '<li><a href="login.php"><i class="fa fa-sign-in" aria-hidden="true"></i> Login</a></li>';
}
?>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav><!--Of navbar -->
<div class="container">
<div id="ctn1">
<form enctype="multipart/form-data" method="post" action="aggiungi_immagini.php">
<div class="fileUpload btn btn-primary">
<span>Seleziona Immagini</span>
<input id="uploadBtn" class="upload" type="file" name="files[]" multiple>
</div>
<input id="uploadFile" placeholder="Nessun File selezionato" disabled="disabled" /><br>
<input type="submit" value="Carica" class="btn btn-primary">
</form><br>
<?php
$valid_formats = array("gif","jpg","jpeg","png","wbmp","bmp","webp","xbm","xpm");
$max_file_size = 80*1024^2; //10 MB
$path = "images/".$_SESSION['prodid']."/"; // Upload directory
$count = 1;
$picid=$id;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Ripeto per ogni file caricato
?><div id="ctnmultiimages" style="heigth:300px;"><?php
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Salto se ci sono stati errori
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Salto per i formati troppo grandi
}
elseif(! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats)){
$message[] = "$name is not a valid format";
continue; // Salto per i formati non validi
}
else{ // Nessun errore, sposta i file
$kaboom = explode(".", $name); // Split file name into an array using the dot
$fileExt = end($kaboom);
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], "images/".$id."/".$name)){
$count++;
}
}
}
}
}
$files = array();
foreach (new DirectoryIterator('images/'.$_SESSION['prodid'].'/') as $fileInfo) {
if($fileInfo->isDot() || !$fileInfo->isFile()) continue;
$files[] = $fileInfo->getFilename();
}
foreach ($files as $filename) {
?>
<style>
#imagelisticon{
color: rgba(255, 255, 255, 0.5);
position: absolute;
margin-left:-100px;
z-index: 2;
background-color: rgba(0, 0, 0, 0.2);
line-height: 200px;
height: 200px;
width:200px;
font-size: 40px;
}
#imgcnt{
background-size: cover;
background-repeat: no-repeat;
position:relative;
margin-top:40px;
width:200px;
height:200px;
display: inline-block;
border: 1px solid lightgrey;
line-height: 198px;
overflow: hidden;
}
.trash{
position: absolute;
vertical-align: text-top;
margin-top: 5px;
margin-left: 50px;
z-index:3;
}
</style>
<div id="imgcnt" style="background-image: url('images/<?php echo $id;?>/<?php echo $filename;?>');">
<div id="<?php echo $filename;?>" class="btn btn-danger trash"><i class="fa fa-trash" aria-hidden="true"></i></div>
<i id="imagelisticon" class="fa fa-check" aria-hidden="true"></i>
</div>
<?php
}
?></div><br>
<center><a href="modifica_prodotto.php"><div class="btn btn-success">
Conferma
</div></a></center><?php
?>
</body>
</html>
<script>
document.getElementById("uploadBtn").onchange = function() {
document.getElementById("uploadFile").value = this.value;
};
$("DIV[class='btn btn-danger trash']").click(function(){
var delfile = ($(this).attr("id"))
$.ajax({
type: 'post',
url: 'delete.php',
data: {
source1: delfile
},
success: function(data) {
console.log(data);
}
});
location.reload()
})
</script>
這是上裝部分
<?php
$valid_formats = array("gif","jpg","jpeg","png","wbmp","bmp","webp","xbm","xpm");
$max_file_size = 80*1024^2; //10 MB
$path = "images/".$_SESSION['prodid']."/"; // Upload directory
$count = 1;
$picid=$id;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Repeat for each uploaded file
?><div id="ctnmultiimages" style="heigth:300px;"><?php
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip if there are errors
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip for too large file
}
elseif(! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats)){
$message[] = "$name is not a valid format";
continue; // Skip for not valid formats
}
else{ // no errors, move files
$kaboom = explode(".", $name); // Split file name into an array using the dot
$fileExt = end($kaboom);
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], "images/".$id."/".$name)){
$count++;
}
}
}
}
}
感謝您的幫助
在您的php.ini文件中檢查max_upload_size變量 –
由於託管網站,我無法訪問php.ini文件,但最大上載大小爲64 MB – valbuxvb