Ciao,
ho questo tipo di problema:
Nel mio sito, quando un utente effettua la registrazione, ha la possibilità di inserire una foto che carica direttamente dal suo pc.
Se l'utente lascia il campo di upload della foto vuoto, il sistema gli assegna
un'immagine di default (noavatar.gif).
Vorrei modificare lo script in modo tale che se l'utente lascia vuoto il campo di upload, il sistema gli assegna un immagine random pescata in una cartella del server.
Mi potete dare qualche suggerimento?
Grazie
Questo è il codice della pagina
[PHP] <?
include "init.php";
$title = "www.recensire.it - Pagina di Registrazione";
$desc = "Pagina di registrazione del sito www.recensire.it";
$sscript = "";
$random_rss = get_random_rss();
include "./header.php";
if(!isset($_GET['action'])) {
$extra = "";
$link = "./authors.php?action=register_ok";
$temp = template("./templates/register");
eval("\$show_register_form = \"$temp\";");
}
else {
if ($action=="register_ok") {
check_magic_quotes();
foreach($_POST as $key => $val)
$_POST[$key] = addslashes(trim($val));
if($_POST['a_pass1'] != $_POST['a_pass2']) {
echo "<br><br><br><center>Password non corretta.<br><a href='javascript:history.go(-1);'>torna indietro e correggi l'errore.</a></center>";
mysql_close();
die();
}
if(!valid_email($_POST['a_email']) ) {
echo "<br><br><br><center>Indirizzo email non valido<br><a href='javascript:history.go(-1);'>torna indietro e correggi l'errore.</a></center>";
mysql_close();
die();
}
query("INSERT INTO {$prefix}subscribers
(fname
,email
)
VALUES('$a_username','$a_email')
") or report("msg","Unknown data corruption");
if (is_uploaded_file($_FILES['a_img_file']['tmp_name'])) {
$fext=explode(".",$_FILES['a_img_file']['name']);
$newname = time()."_avatar.$fext[1]";
move_uploaded_file($_FILES['a_img_file']['tmp_name'], "./images/author_pics/$newname");
} else $newname = "noavatar.gif";
$a_reg_date = time();
$a_group = 3;
$p = md5($_POST['a_pass1']);
if(!@query("insert into `{$prefix}authors` (aut_username , aut_password, aut_email, aut_group, aut_bio, aut_location, aut_website, aut_image, aut_reg_date, aut_validating)
VALUES('$_POST[a_username]','$p','$_POST[a_email]',$a_group,'$_POST[a_bio]','$_POST[a_location]','$_POST[a_website]','$newname',$a_reg_date,0);")) {
@unlink("./images/author_pics/$newname");
cdie("<br><br><br><br><center>Questo Username e' gia' presente nel nostro database. Inserisci un altro Username.<br><a href='javascript:history.go(-1);'>torna indietro e correggi l'errore.</a></center>");
}
$id = mysql_insert_id();
if($newname == "noavatar.gif") {
copy("./images/author_pics/noavatar.gif","./images/author_pics/noavatar_copy.gif");
@rename("./images/author_pics/$newname",@"./images/author_pics/$id.$fext[1]");
$r = query("UPDATE {$prefix}authors
SET aut_image='$newname' WHERE aut_id=$id") or report();
} else
@rename("./images/author_pics/$newname",@"./images/author_pics/$id.$fext[1]");
$r = query("UPDATE {$prefix}authors
SET aut_image='$id.$fext[1]' WHERE aut_id=$id") or report();
@rename("./images/author_pics/noavatar_copy.gif",@"./images/author_pics/noavatar.gif");
$show_register_form = "<br><center><b>Registrazione Completata</b> Usa Username e Password per entrare.
$to = $_POST["a_email"];
$from = www.recensire.it;
$message = "
Gentile $a_username
Recensire ti da il benvenuto nella sua community!
Questi sono i tuoi dati di accesso
username : $a_username
password : $a_pass1
Grazie,
Lo staff di
www.recensire.it
[email protected]";
mail($to, "Benvenuto su www.recensire.it", $message, "From: "Admin" <$from>");
}
}
$temp = template("./templates/top");
eval("\$top = \"$temp\";");
$left_main_categories = get_cats();
$temp = template("./templates/new_category");
eval("\$new_category = \"$temp\";");
$temp = template("./templates/ads");
eval("\$ads = \"$temp\";");
$temp = template("./templates/left_more_options");
eval("\$left_more_options = \"$temp\";");
$temp = template("./templates/left_newsletter");
eval("\$left_newsletter = \"$temp\";");
$temp = template("./templates/top2");
eval("\$top2 = \"$temp\";");
$right_random_article = get_random_art();
$right_statistics = get_stats();
$temp = template("./templates/sponsor");
eval("\$sponsor = \"$temp\";");
$temp = template("./templates/top_site_search");
eval("\$top_site_search = \"$temp\";");
$left="$top$left_main_categories<br>$new_category<br>$ads<br>$left_newsletter<br>";
$center = "$top_site_search $show_register_form";
$right = "$top2$right_random_article<br>$right_statistics<br>$sponsor<br>";
$temp = template("./templates/center_main");
eval("\$center_main = \"$temp\";");
echo $center_main;
$temp = template("./templates/footer");
eval("\$footer = \"$temp\";");
echo $footer;
@mysql_close();
?>[/PHP]