salve a tutti è da qualche giorno che ho deciso di implementare il resize delle foto caricate dagli utenti iscritti ad una community che sto creando.
In pratica ho una pagina modifica_profilo.php dalla quale è possibile fare l'upload dell'immagine da associare al proprio profilo utilizzando il seguente cosice:
Codice PHP:
<?
include_once("include/config.php");
include_once("include/auth.lib.php");
include_once("include/reg.lib.php");
list($status, $user) = auth_get_status();
if ($status == AUTH_LOGGED){
if ((isset($_GET["id"])) AND ($prof = get_profilo($user["id_user"]))){
?>
// ...segue codice html
<?
if ((isset($_POST["Submit"])) AND ($_POST["Submit"]=="Invia")){
$ok = true;
$foto_name = $_FILES["Foto"]["name"];
if ($foto_name == " ") {
$endresult = "Nessuna foto selezionata.";
$ok = false;
}else{
$ext = strrchr($foto_name,'.');
if (($ext != ".gif") AND ($ext != ".jpg") AND ($ext != ".jpeg") ) {
$endresult = "La foto ha un estensione non consentita.";
$ok = false;
}else{
if(@is_uploaded_file($_FILES["Foto"]["tmp_name"])) {
if (($user["foto"] != '') AND( file_exists($_CONFIG["path_foto"].$user["foto"]))){
$successo = unlink($_CONFIG["path_foto"].$user["foto"]) or die ("Errore");
}
@move_uploaded_file($_FILES["Foto"]["tmp_name"], $_CONFIG["path_foto"].$user["id_user"].$ext) or $endresult = "Impossibile caricare la foto per un errore interno al server.";
}}}
$ret = reg_check_data($_POST);
if ($ok){
$status = ($ret === true) ? reg_mod_register($_POST,$_GET["id"],$user["id_user"].$ext) : REG_ERRORS;
}else{
$status = ($ret === true) ? reg_mod_register($_POST,$_GET["id"],'') : REG_ERRORS;
}
echo "<tr><td class='cellasezioni' align='center'>";
switch($status){
case REG_ERRORS:?>
<?php
foreach($ret as $error)
printf("[b]%s[/b]: %s
", $error[0], $error[1]);?>
Premere "indietro" per modificare i dati
<?php
break;
case REG_FAILED:
echo "Modifica Fallita a causa di un errore interno.";
break;
case REG_SUCCESS:
header("Refresh: 3;URL=home.php".$link."&p=profilo&id=".$_GET["id"]."&update=y");
if ($ok){
echo "Foto caricata con successo.
";
}else{
echo $endresult."
";
}
echo "Modifica dati profilo avvenuta con successo.";
break;
}
echo "</td></tr>";
}else{
?>
la funzione che mi permette di effettuare l'upload è la seguente:
Codice PHP:
function uploadFile($path, $file, $arr){
$ok=true;
$endresult="";
$foto_name = $file["name"];
$size = $file["size"]/1600;
if ($foto_name == "") {
$endresult = "Nessuna file selezionato.";
$ok = false;
}else{
$ext = explode('.', $foto_name);
$pos = sizeof($ext) - 1;
if (!in_array($ext[$pos],$arr)) {
$endresult = "Il File ha un estensione non consentita.";
$ok = false;
}else{
if($size>1600){
$endresult = "Il File è troppo grande. Riprova con uno più piccolo.";
$ok = false;
}else{
if(@is_uploaded_file($file["tmp_name"])) {
$path_foto = $path.$foto_name;
if (file_exists($path_foto)){
$endresult = "Il File già esiste. Prova a rinominarlo.";
$ok = false;
}else{
if(@move_uploaded_file($file["tmp_name"], $path_foto)){
$ok= true;
$endresult = "File caricato correttamente.";
}else{
$endresult = "Impossibile caricare il file per un errore interno al server.";
$ok= false;
} //FINE IF move_upload
}// FINE IF FILE GIà ESISTENTE
}// FINE IF is_uploaded
}// FINE IF $size
}// FINE IF estensione
}// FINE IF $foto_name
return array($ok,$endresult,$foto_name);
}
in questo modo le foto caricate vanno nella cartella pubblic ed inoltre il nome del file caricato vinee cambiato con l'id dell'utente
il form per modificare il profilo è il seguente:
Codice PHP:
<form action="home.php<?=$link?>&p=mod_profilo&id=<? echo $_GET["id"];?>" method="post" enctype="multipart/form-data" name="form1">
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="3">
<tr valign="top">
<td width="247"> <table width="63%" border="0" align="center" cellpadding="0" cellspacing="3">
<tr>
<td align="center"height="150">
<? if (($prof["foto"]!='') AND (file_exists($_CONFIG["path_foto"].$prof["foto"]))){ ?>
[img]<? echo [/img]" width="150" height="150" alt="">
<? }else{ echo ""; } ?>
</td>
</tr>
</table></td>
<td width="266"> <table width="100%" border="0" align="right" cellpadding="0" cellspacing="3">
<tr>
<td>INFORMAZIONI UTENTE</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="52%"><div align="left">[b]Nome:[/b]</div></td>
<td width="48%"><div align="right">
<input name="Nome" type="text" value="<?=$prof['name']?>">
</div></td>
</tr>
<tr>
<td><div align="left">[b]Cognome:[/b]</div></td>
<td><div align="right">
<input name="Cognome" type="text" value="<?=$prof['surname']?>">
</div></td>
</tr>
<tr>
<td><div align="left">[b]Città:[/b]</div></td>
<td><div align="right">
<input name="Citta" type="text" value="<?=$prof['localita']?>"></div></td>
</tr>
<tr>
<td><div align="left">[b]Data di Nascita:[/b]</div></td>
<td>
<div align="right">
<? $data_m = explode("-",$prof["datanascita"]);?>
<input name="Datanascita" type="text" value="<? echo $data_m[2]."/".$data_m[1]."/".$data_m[0];?>">
</div></td>
</tr>
<tr>
<td><div align="left">[b]Sesso:[/b]</div></td>
<td><div align="right">
<input name="Sesso" type="radio" value="m" <? if ($prof["sesso"] == "m"){ echo "checked"; }?>>
M
<input type="radio" name="Sesso" value="f" <? if ($prof["sesso"] == "f"){ echo "checked"; }?>>
F</div></td>
</tr>
<tr>
<td><div align="left">[b]E-Mail:[/b]</div></td>
<td><div align="right">
<input name="Email" type="text" id="Email2" value="<?=$prof['email']?>">
</div></td>
</tr>
<tr>
<td><div align="left">[b]Password:[/b]</div></td>
<td><div align="right">
<input name="Password" type="text" id="Password2" value="<?=$prof['PASSWORD']?>">
</div></td>
</tr>
</table>
</td>
</tr>
</table>
</tr>
<tr valign="top">
<td colspan="2" align="right"><table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="41%" valign="top"></td>
<td width="59%" valign="top">DESCRIZIONE:</td>
</tr>
<tr>
<td height="83" colspan="2" align="center" valign="top"> <div align="right">
<textarea name="Descrizione" cols="40" rows="5"><? echo estrazione_dati($prof["descrizione"]); ?></textarea>
</div></td>
</tr>
</table></td>
</tr>
<tr align="right" valign="top">
<td colspan="2">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="41%" valign="top"><div align="left"></div></td>
<td width="59%" valign="top">FOTO:</td>
</tr>
<tr>
<td colspan="2" align="right" valign="top"><input name="Foto" type="file" id="Foto" size="40"> </td>
</tr>
</table></td>
</tr>
<tr align="right" valign="top">
<td colspan="2"> <input type="submit" name="Submit" value="Invia">
</td>
</tr>
</table>
</form>
A questo punto sapreste indicarmi come devo agire per poter modificare il codice.