Allora
Ho una pagina per uploadare le immagini e relative descrizioni.
Codice PHP:
<?php
session_start();
function rindirizzo($url, $seconds = FALSE){
if (!headers_sent() && $seconds == FALSE){
header("Refresh: ".$seconds.";URL=" . $url);
}
else{
if ($seconds == FALSE){
$seconds = "0";
}
echo "<meta http-equiv=\"refresh\" content=\"$seconds;url=$url\">";
}
}
include ("login/my_config.php");
Pagina_protetta();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="en-au" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
<link rel="stylesheet" type="text/css" href="template/site/conf/style.css" />
<style type="text/css">
.style1 {
font-size: large;
text-align: center;
}
.style2 {
text-align: center;
}
.style3 {
font-size: large;
text-align: center;
color: #FFFFFF;
background-color: #003300;
}
</style>
<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "simple"
});
</script>
<script language="javascript" type="text/javascript">
function LimitInput(jsField, CounterField, MaxNum) {
if (jsField.value.length > MaxNum) {
jsField.value = jsField.value.substring(0, MaxNum);
} else {
CounterField.value = MaxNum - jsField.value.length;
}
}
</script>
</head>
</table>
<div align="center">
<table border="0" width="250" height="50">
<tr>
<td height="93" width="100"><a href="manager.php">
[img]images/button_gest.gif[/img]</a></td>
<td height="93" width="50"></td>
<td height="93" width="100"><a href="index.php">
[img]images/button_gal.gif[/img]</a></td>
</tr>
</table>
</div>
[b]Inserisci un titolo di max 25 caratteri e una descrizione di max 150 caratteri;
I file supportati sono di tipo: Jpeg, Gif e PNG;
La dimensione dell'immagine non può superare i 2MB.[/b]
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
Titolo:
<input name="titolo" type="text" size="25" maxlength="25" onkeydown="LimitInput(this.form.titolo,this.form.textcount,25);" onkeyup="LimitInput(this.form.titolo,this.form.textcount,25);"/>
<font size="2">Caratteri rimanenti:</font> <input readonly type="text" name="textcount" size="2" value="25">
Descrizione:
<textarea name="descrizione" cols="20" rows="4">
</textarea>
Immagine:
<input type="file" name="imagefile">
<input type="submit" name="Submit" value="Submit">
</form>
<?php
$t=time();
if(isset($_POST['Submit'])){
// faccio un po' di inclusioni...
@include 'config.php';
@require 'function.php';
@require 'function_res.php';
$iduser=$_SESSION['iduser'];
$cartella=$_SESSION['cartella'];
$carfoto_user = $path_imgp.$cartella."/";
$carthumb_user = $path_imgt.$cartella."/";
// Creo una array con i formati accettati
$tipi_consentiti = array("image/gif","image/jpeg","image/png");
// recupero i dati dal form
$titolo = @addslashes($_POST['titolo']);
$descrizione = @addslashes($_POST['descrizione']);
$nome = @addslashes($_FILES['imagefile']['name']);
$path = $carfoto_user . stripslashes($nome);
$tipo = @addslashes($_FILES['imagefile']['type']);
$massimo_tit = 25;
$massimo_des = 150;
$massimo_nome = 30;
if ((strlen($titolo) > $massimo_tit) && (strlen($descrizione) > $massimo_des))
{
echo "Inserire un titolo di massimo <font color=\"#FF0000\"> [b]" . $massimo_tit . "[/b]</font>
caratteri una descrizione di massimo <font color=\"#FF0000\"> [b]" . $massimo_des . "[/b]</font> caratteri
";
}
elseif (strlen($titolo) > $massimo_tit)
{
echo "Inserire un titolo di massimo <font color=\"#FF0000\"> [b]" . $massimo_tit . "[/b]</font> caratteri
";
}
elseif (strlen($descrizione) > $massimo_des)
{
echo "Inserire una descrizione di massimo <font color=\"#FF0000\"> [b] " . $massimo_des . "[/b]</font> caratteri
";
}
elseif (strlen($nome) > $massimo_nome)
{
echo "Il nome dell'immagine deve essere massimo di <font color=\"#FF0000\"> [b] " . $massimo_nome . "[/b]</font> caratteri
";
}
else {
$titolo = HtmlEntities($titolo, ENT_COMPAT, "UTF-8");
// verifico che il formato del file sia tra quelli accettati
if ((@in_array($_FILES['imagefile']['type'], $tipi_consentiti))&& ($_FILES["imagefile"]["size"] < 2200000)){
// copio il file nella cartella delle immagini
@copy ($_FILES['imagefile']['tmp_name'], $carfoto_user . $nome);
$nomenew = $t."_".$nome;
// creo ridimensionamento
@makeresize($carfoto_user,$path,$nomenew,$tipo);
// creo la miniatura
@makeThumb($carthumb_user,$path,$nomenew,$tipo);
unlink($carfoto_user.$nome);
$min= "tb_" . $nomenew;
// aggiorno il database
$query = "INSERT INTO images (id_user,Titolo,Descrizione,Nome,Tipo,thumb) VALUES('$iduser','$titolo','$descrizione','$nomenew','$tipo','$min')";
$res = @mysql_query($query) or die (mysql_error());
@mysql_close($cn);
rindirizzo("ok.php",0);
}else{
// stampo un messaggio di errore nel caso in cui il file sia di un formato non consentito
echo "Impossibile eseguire l'upload. Formato non consentito o immagine troppo grande!";
}
}
}
?>
Ho scoperto che questa pagina con IE 7 non funziona.
In pratica non riesco a caricare niente..mi ritrovo sempre con il messaggio di errore dell'ELSE di cui sopra.
Con Firefox nessun problema invece.
Come mai?
Grazie