• User Newbie

    Aiuto per Random

    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]


  • User Attivo

    questo script l'avevo fatto 5-6 anni fa 😄
    è rimasto solo in qualche sito russo..
    cmq, funziona così, legge tutti i files da una cartella, se sono .gif o .GIF le mette in un array numerato, poi genera un numero rand e pesca l'immagine dall'array

    [php]
    <?php
    #This script has been developped by Francesco D'Alesio [[email protected]]
    #Please feel free to contact me for any reason
    #All you have to do is to change this two variables. Remember to use the absolute path for the first variable, starting with a slash
    $absolute = "mes_images_a_afficher";
    $url = "http://www.monsite.com/mesphotos/mes_images_a_afficher";
    #You may now add in the img html tag the url of this script
    #<IMG SRC="http://yourdomain.com/whatever/imgrandom.php3">

    DO NOT CHANGE ANYTHING BELOW THIS LINE

    $randir = dir("$absolute");
    $num = 0;
    while($read = readdir($randir))
    {
    if ($tmp[1] == "gif" || $tmp[1] == "GIF")
    {
    $imgsrc[] = $read;
    $num++;
    }
    }
    srand((double)microtime()*1000000);
    $imgrandom = rand(0,($num-1));
    header("location: $url/$imgsrc[$imgrandom]");
    ?>

    [/php]poi invece che fare header...
    prendi l'immagine e la usi per i tuoi scopi

    se hai dubbi chiedi
    :ciauz:


  • User Newbie

    Grazie Mille,
    appena riesco lo provo e ti so dire;)


  • User Newbie

    @fdalesio said:

    questo script l'avevo fatto 5-6 anni fa 😄
    è rimasto solo in qualche sito russo..
    cmq, funziona così, legge tutti i files da una cartella, se sono .gif o .GIF le mette in un array numerato, poi genera un numero rand e pesca l'immagine dall'array

    [php]
    <?php
    #This script has been developped by Francesco D'Alesio [[email protected]]
    #Please feel free to contact me for any reason
    #All you have to do is to change this two variables. Remember to use the absolute path for the first variable, starting with a slash
    $absolute = "mes_images_a_afficher";
    $url = "http://www.monsite.com/mesphotos/mes_images_a_afficher";
    #You may now add in the img html tag the url of this script
    #<IMG SRC="http://yourdomain.com/whatever/imgrandom.php3">

    DO NOT CHANGE ANYTHING BELOW THIS LINE

    $randir = dir("$absolute");
    $num = 0;
    while($read = readdir($randir))
    {
    if ($tmp[1] == "gif" || $tmp[1] == "GIF")
    {
    $imgsrc[] = $read;
    $num++;
    }
    }
    srand((double)microtime()*1000000);
    $imgrandom = rand(0,($num-1));
    header("location: $url/$imgsrc[$imgrandom]");
    ?>

    [/php]poi invece che fare header...
    prendi l'immagine e la usi per i tuoi scopi

    se hai dubbi chiedi
    :ciauz:

    Ho creato una dyrectory "avatar" nella root. All'interno di questa directory ho inserito le immagini. Ho modificato la variabile absolute nel seguente modo: $absolute = "/avatar";

    Ma mi viene restituito il seguente errore:

    Warning: dir(/www.recensire.it/avatar/) [function.dir]: failed to open dir: No such file or directory in /mounted-storage/home15a/sub003/sc17766-MZEK/www.recensire.it/random.php on line **10

    **Cosa può essere?

    Grazie


  • User Attivo

    che quella dir non esiste..
    lì ci devi mettere il path assoluto della cartella...
    nel tuo caso è questo, guardando l'errore che hai postato è questo
    **/mounted-storage/home15a/sub003/sc17766-MZEK/www.recensire.it/avatar/

    **vedi un pò, fammi sapere