Dunque, ho verificato che il problema non è nel database perché le immagini oltre la ventesima non vengono salvate neppure su cartella. Resta il fatto che succede solo su quel host.
Vi posto tutti i codici, ditemi se c'è un motivo per il quale dovrebbe fermarsi al ventesimo caricamento.
Grazie
Pagina con il form di caricamento e modifica
codice HTML:
<div id="wrapper">
<div id="home"></div>
<?php include 'extended/gallery_menu.php';?>
<div id="sottomenu"></div>
<div id="primafascia">
<div id="logo2"><img src="images/logo.png" alt="" /></div>
<div class="title">
<h1>Galleria</h1>
</div>
<h2>Eventi</h2>
<form method="post" enctype="multipart/form-data">
<?php
$categoria = eventi;
$sql="SELECT * FROM `galleria` WHERE categoria='$categoria'";
$dati=mysql_query($sql);
while($row=mysql_fetch_array($dati))
{
?>
<div class="quadro">
<button class="cancella elimina" type="submit" formaction="db/delete.php?gallery&categoria=<?php echo $row['categoria']; ?>&id=<?php echo $row["id"]; ?>"><img src="images/icone/chiudi.png" alt="elimina"></button>
<div class="cornice">
<div class="galleryimg" style="background:#000 url(data:<?php echo $row['type']; ?>;base64,<?php echo $row['thumb']; ?>) center center no-repeat; background-size: cover; ">
<a href="<?php echo 'db/getimag.php?id='.$row['id'] ;?>"><img src="images/mascherina.png" alt="clicca per ingrandire" title="clicca per ingrandire"></a>
</div>
</div>
<div class="clear"></div>
<input class="header3" style="width:98%" type="text" name="titolo[]" value="<?php echo $row['titolo']; ?>" placeholder="Qui il titolo" />
<input class="aggiungi bottom" type="file" name="modifica[]" placeholder="modifica" />
<input class="nascosto" type="text" name="id[]" value="<?php echo $row["id"]; ?>" />
<div class="clear"></div>
</div>
<?php
}
?>
<div class="quadro abbassa">
<div class="cornice">
<div class="galleryimg">
<img src="images/icone/add.jpg" alt="clicca per aggiungere un file" title="clicca per aggiungere un file">
<input class="add" type="file" name="userFile" />
</div>
</div>
<input class="aggiungi bottom width100" type="text" name="nuovo" placeholder="Qui il titolo" />
</div>
<input class="nascosto" type="text" name="key" value="<?php echo $key; ?>" />
<input class="nascosto" type="text" name="categoria" value="<?php echo $categoria ; ?>" />
<button class="salva" type="submit" formaction="db/gallery_upload.php">Salva</button>
</form>
</div>
<?php include 'extended/footer.php';?>
</div><!--wrapper-->
Pagina gallery_upload
Codice PHP:
<!DOCTYPE html>
<html lang="it">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body onload="document.forms[0].submit();">
<?php
include '../db/connessione.php';
$id = $_POST['id'];
$newid = $_POST['id'];
$titolo = $_POST['titolo'];
$nuovo = $_POST['nuovo'];
$percorsothumb = '../images/thumbs/galleria/';
$percorsoimg = '../images/galleria/';
$nomeimg = $_FILES['userFile']['name'];
$categoria = $_POST['categoria'];
if(get_magic_quotes_gpc()) {$nuovo = stripslashes($nuovo);}
$nuovo = mysql_real_escape_string($nuovo);
//se sto caricando una nuova foto
if (!empty($_FILES['userFile']['type']))
{
// Ottengo le informazioni sull'immagine originale
list($width, $height, $type, $attr) = getimagesize ($_FILES['userFile']['tmp_name']);
//controllo se l'estensione è supportata
if ($type==1) $estensione=gif;
else if ($type==2) $estensione=jpeg;
else if ($type==3) $estensione=png;
else die ('<h1>Errore</h1><br/><h3>Estensione del file non supportata</h3>');
//verifico il file
$handle = fopen ($_FILES['userFile']['tmp_name'], "r+") or die ('<h1>Errore</h1><br/><h3>impossibile aprire il file</h3>');
$image = fread ($handle, filesize($_FILES['userFile']['tmp_name'])) or die('<h1>Errore</h1><br/><h3>impossibile leggere il file</h3>');
fclose ($handle);
$type = 'image/'.$estensione;
//ridimensiono l'immagine
include'../db/resizegallery.php';
//converto le immagini
$thumb = base64_encode(file_get_contents("$percorsothumb$nomeimg"));
$image = base64_encode(file_get_contents("$percorsoimg$nomeimg"));
//inserisco nel database
$query = 'INSERT INTO galleria (titolo,immagine,thumb,type,estensione,categoria) VALUES ("' . $nuovo . '","' . $image . '","' . $thumb . '","' . $type. '","' . $estensione . '","' . $categoria . '")';
$result = mysql_query($query);
//se ci sono errori mi fermo se no..
if (!$result) {die("Errore:" . mysql_error());}
else {
//se si stanno aggiornano
if (isset($_FILES['modifica']))
{
//creo un array
$array = array_combine($id, $_FILES['modifica']['tmp_name']);
///faccio un ciclo delle immagini presenti
foreach ($array as $id => $_FILES['modifica']['tmp_name'])
{
if (!empty($_FILES['modifica']['tmp_name']))
{
// Ottengo le informazioni sull'immagine originale
list($width, $height, $type, $attr) = getimagesize ($_FILES['modifica']['tmp_name']);
if ($type==1) $estensione=gif;
else if ($type==2) $estensione=jpeg;
else if ($type==3) $estensione=png;
else die ('<h1>Errore</h1><br/><h3>Estensione del file non supportata</h3>');
//verifico il file
$handle = fopen ($_FILES['modifica']['tmp_name'], "r") or die ('<h1>Errore</h1><br/><h3>impossibile aprire il file</h3>');
$image = fread ($handle, filesize($_FILES['modifica']['tmp_name'])) or die('<h1>Errore</h1><br/><h3>impossibile leggere il file</h3>');
fclose ($handle);
//nuove variabili del file
$nomeimg = $id;
$type = 'image/'.$estensione;
//ridimensiono l'immagine
include'../db/resize2.php';
//converto il file
$thumb = base64_encode(file_get_contents("$percorsothumb$nomeimg.$estensione"));
$image = base64_encode(file_get_contents("$percorsoimg$nomeimg.$estensione"));
//..aggiorno il database
$query = "UPDATE galleria SET
titolo = '" . $titolo . "',
immagine = '" . $image . "',
thumb = '" . $thumb . "',
type = '" . $type . "',
estensione = '" . $estensione . "',
categoria = '" . $categoria . "'
WHERE id=$id";
$result = mysql_query($query);
if (!$result) {die("Errore:" . mysql_error());}
else{
?>
<form action="../<?php echo $categoria ; ?>.php?modifica" method="post">
<input type="hidden" name="var1" value="entra">
</form>
<?php
};
} else {
?>
<form action="../<?php echo $categoria ; ?>.php?modifica" method="post">
<input type="hidden" name="var1" value="entra">
</form>
<?php
};
};
} else {
?>
<form action="../<?php echo $categoria ; ?>.php?modifica" method="post">
<input type="hidden" name="var1" value="entra">
</form>
<?php
};
};
//se non sto caricando una nuova foto
} else if (empty($_FILES['userFile']['type']))
{
//aggiorno tutti i titolo
$array = array_combine($id, $titolo);
foreach ($array as $id => $titolo)
{
if(get_magic_quotes_gpc()) {$titolo = stripslashes($titolo);}
$titolo = mysql_real_escape_string($titolo);
$query = "UPDATE galleria SET
titolo = '". $titolo ."'
WHERE id=$id";
$result = mysql_query($query);
}
//se si stanno aggiornano le foto
if (isset($_FILES['modifica']))
{
$array = array_combine($newid, $_FILES['modifica']['tmp_name']);
///faccio un ciclo delle immagini presenti
foreach ($array as $newid => $_FILES['modifica']['tmp_name'])
{
if (!empty($_FILES['modifica']['tmp_name']))
{
// Ottengo le informazioni sull'immagine originale
list($width, $height, $type, $attr) = getimagesize ($_FILES['modifica']['tmp_name']);
if ($type==1) $estensione=gif;
else if ($type==2) $estensione=jpeg;
else if ($type==3) $estensione=png;
else die ('<h1>Errore</h1><br/><h3>Estensione del file non supportata</h3>');
//verifico il file
$handle = fopen ($_FILES['modifica']['tmp_name'], "r") or die ('<h1>Errore</h1><br/><h3>impossibile aprire il file</h3>');
$image = fread ($handle, filesize($_FILES['modifica']['tmp_name'])) or die('<h1>Errore</h1><br/><h3>impossibile leggere il file</h3>');
fclose ($handle);
//nuove variabili del file
$nomeimg = $newid;
$type = 'image/'.$estensione;
//ridimensiono l'immagine
include'../db/resize2.php';
//converto il file
$thumb = base64_encode(file_get_contents("$percorsothumb$nomeimg.$estensione"));
$image = base64_encode(file_get_contents("$percorsoimg$nomeimg.$estensione"));
//..aggiorno il database
$query = "UPDATE galleria SET
immagine = '" . $image . "',
thumb = '" . $thumb . "',
type = '" . $type . "',
estensione = '" . $estensione . "',
categoria = '" . $categoria . "'
WHERE id=$newid";
$result = mysql_query($query);
if (!$result) {die("Errore:" . mysql_error());}
else {
?>
<form action="../<?php echo $categoria ; ?>.php?modifica" method="post">
<input type="hidden" name="var1" value="entra">
</form>
<?php
};
} else {
?>
<form action="../<?php echo $categoria ; ?>.php?modifica" method="post">
<input type="hidden" name="var1" value="entra">
</form>
<?php
};
};
} else {
?>
<form action="../<?php echo $categoria ; ?>.php?modifica" method="post">
<input type="hidden" name="var1" value="entra">
</form>
<?php
};
};
?>
</body>
</html>
Codice per il resize
Codice PHP:
<?php
//Calcolo dimensioni thumbs
$percent = $width / $height;
$thumbheight = 300;
$thumbwidth = $percent * $thumbheight;
//calcolo dimensioni immagine grande
If ($height >=768)
{
$bigheight = 768;
$bigwidth = $percent * $bigheight;
} else {
$bigheight = $height;
$bigwidth = $width;
};
$thumb = imagecreatetruecolor($thumbwidth, $thumbheight);
$image = imagecreatetruecolor($bigwidth, $bigheight);
imagealphablending($thumb, false);
imagealphablending($image, false);
imagesavealpha($thumb, true);
imagesavealpha($image, true);
// Creo la versione thumb
if ($estensione==jpeg) {
$source = imagecreatefromjpeg ($_FILES['userFile']['tmp_name']);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumbwidth, $thumbheight, $width, $height);
imagecopyresampled($image, $source, 0, 0, 0, 0, $bigwidth, $bigheight, $width, $height);
// Salvo l'immagine ridimensionata
imagejpeg($thumb,"$percorsothumb$nomeimg",100);
imagejpeg($image,"$percorsoimg$nomeimg",85);
} else if ($estensione==png) {
$source = imagecreatefrompng ($_FILES['userFile']['tmp_name']);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumbwidth, $thumbheight, $width, $height);
imagecopyresampled($image, $source, 0, 0, 0, 0, $bigwidth, $bigheight, $width, $height);
// Salvo l'immagine ridimensionata
imagepng($thumb,"$percorsothumb$nomeimg");
imagepng($image,"$percorsoimg$nomeimg");
} else if ($estensione==gif) {
$source = imagecreatefromgif ($_FILES['userFile']['tmp_name']);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumbwidth, $thumbheight, $width, $height);
imagecopyresampled($image, $source, 0, 0, 0, 0, $bigwidth, $bigheight, $width, $height);
// Salvo l'immagine ridimensionata
imagegif($thumb,"$percorsothumb$nomeimg");
imagegif($image,"$percorsoimg$nomeimg");
};
//Svuoto la memoria
ImageDestroy($thumb);
ImageDestroy($source);
ImageDestroy($image);
?>