Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 29
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    208

    estrarre le foto inserite dall'utente loggato

    per richiamare le foto ho usato questo script, ma non mi carica la foto, perché?

    <img src= "public/foto_utente/<?php echo $row['foto']; ?>" ?>

    o per la minuatura

    <img src= "public/foto_utente_thumbs/<?php echo $row['foto']; ?>" ?>

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    208
    up

  3. #3
    Se la cartella public è nella root dello script
    Codice PHP:
    <img src= "/public/foto_utente/<?php echo $row['foto']; ?>" >
    Se la cartella public è nella root del sito principale e lo script è dentro un'altra acrtella
    Codice PHP:
    <img src= "../public/foto_utente/<?php echo $row['foto']; ?>" >
    attenzione alla chiusura del tag img > e non ?>
    MEMENTO AUDERE SEMPER
    Maxxl

    www.maxxl.it

  4. #4
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,591
    ..quel codice te lo avevo scritto COME ESEMPIO..
    per richiamarla correttamente tocca vedere come hai nominato il recordset..
    metti il codice così ti si aiuta..

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    208
    ho un form dove posso far inserire le foto:

    Codice PHP:

    <form action="modifiche_utente/modifica_foto.php" method="post" enctype="multipart/form-data" name="modifica_foto" id="modifica_foto"
          <
    label><input type="hidden" name="MAX_FILE_SIZE" value="8000000" /> 
          <
    input name="foto" type="file" class="Stile1" size="30" /> 
          </
    label
          <
    label
          <
    input type="submit" class="Stile1" value="Invia" /> 
          </
    label
                    </
    form
    la pagina modifica_foto.php ha questo script:

    Codice PHP:

    ........... 

    session_start();  

    $query "UPDATE tabella SET foto='" $_FILES['foto']['modifica_foto']  . "' WHERE utente ='" $_SESSION['utente'] . "'";  
    mysql_query($query);  


    //percorsi cartelle per il caricamento dei files   
    $cartella_thumbs "../public/foto_utente_thumbs/";   
    $cartella_upload "../public/foto_utente/";   

    //la larghezza delle miniature, in pixel   
    $img_thumb_width 120;   

    {  
    //verifica le dimensioni del file caricato   
    if($_FILES['foto']['size'] ==0)   
    {      
      die(
    'Errore : campo upload nullo');      
    }   

    // Ottengo le informazioni sull'immagine   
    list($width$height$type$attr) = getimagesize($_FILES['foto']['tmp_name']);   
    // Controllo che le dimensioni (in pixel) non superino 600x800   
    if (($width 600) || ($height 800))   
    {   
      die(
    "Dimensioni non corrette");   
    }   

    $file_permessi = array("image/pjpeg","image/jpeg");   
    if(!
    in_array($_FILES['foto']['type'], $file_permessi))   
    {      
    die(
    'Estensione non consentita');      
    }   
    // Verifico che sul sul server non esista già un file con lo stesso nome  
    if (file_exists('../public/foto_utente'.$_FILES['foto']['name']))  
    {      
    die(
    'File già esistente sul server. controlla che non hai gia inserito questa foto o pure prova a rinominarla.');      
    }   
    ///////////////////////  
    //crea la thumbsnail///  
    //////////////////////  
    $ThumbWidth $img_thumb_width;  
    //crea la nuova immagine  
    if($_FILES['foto']['size']){  
    if(
    $_FILES['foto']['type'] == "image/pjpeg" || $_FILES['foto']['type'] == "image/jpeg"){  
    $new_img imagecreatefromjpeg($_FILES['foto']['tmp_name']);  
    }elseif(
    $_FILES['foto']['type'] == "image/x-png" || $_FILES['foto']['type'] == "image/png"){  
    $new_img imagecreatefrompng($_FILES['foto']['tmp_name']);  
    }elseif(
    $_FILES['foto']['type'] == "image/gif"){  
    $new_img imagecreatefromgif($_FILES['foto']['tmp_name']);  
    }  
    //ottiene larghezza e altezza dell'immagine originale.  
    list($width$height) = getimagesize($_FILES['foto']['tmp_name']);  
    //calcola le proporzioni e ottiene dimensioni thumbsnail  
    $imgratio=$width/$height;  
    if (
    $imgratio>1){  
    $newwidth $ThumbWidth;  
    $newheight $ThumbWidth/$imgratio;  
    }else{  
    $newheight $ThumbWidth;  
    $newwidth $ThumbWidth*$imgratio;  
    }  
    //funzione per ridimensionare l'immagine.  
    if (function_exists(imagecreatetruecolor)){  
    $resized_img imagecreatetruecolor($newwidth,$newheight);  
    }else{  
    die(
    "Errore: Assicurati che sul tuo server siano installate le GD library");  
    }  
    //ridimensionamento  
    if($_FILES['foto']['type'] == "image/x-png" || $_FILES['foto']['type'] == "image/png"){  
    imagealphablending($resized_imgfalse);  
    }  
    imagecopyresized($resized_img$new_img0000$newwidth$newheight$width$height);  
    //salva l'immagine  
    $nome_file strtolower($_FILES['foto']['name']);  
    if(
    $_FILES['foto']['type'] == "image/pjpeg" || $_FILES['foto']['type'] == "image/jpeg"){  
    imagejpeg ($resized_img,"$cartella_thumbs/$nome_file");  
    }  
    elseif(
    $_FILES['foto']['type'] == "image/x-png" || $_FILES['foto']['type'] == "image/png"){  
    imagesavealpha($resized_imgtrue);  
    imagepng ($resized_img,"$cartella_thumbs/$nome_file");  
    }  
    elseif(
    $_FILES['foto']['type'] == "image/gif"){  
    imagegif($resized_img,"$cartella_thumbs/$nome_file");  
    }  
    ImageDestroy ($resized_img);  
    ImageDestroy ($new_img);  
    }  
    if(!
    is_uploaded_file($_FILES['foto']['tmp_name']))  
    {die(
    'Erroe nel caricamento');     
    }     
    move_uploaded_file($_FILES['foto']['tmp_name'],$cartella_upload .$nome_file)     
    or die(
    'Non posso caricare il file');  
    echo 
    "L'immagine è stata ridimensionata ed inserita con successo:
     <img src=\"
    $cartella_thumbs/$nome_file\" />
    "
    ;  
    }  
    ?> 
    il codice funziona correttamente, nel senso che mi carica la foto normale (su "../public/foto_utente/") e quella ridotta (su "../public/foto_utente_thumbs/")

    ma se voglio vedere la foto con questo codice:

    Codice PHP:

    <img src= "../public/foto_utente_thumbs/<?php echo $row['foto']; ?>" >


    mi compare 1 rettangolo con una x rossa al centro (quindi non la trova)

    dove sta il problema?

  6. #6
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,591
    SCHERZI? hai letto quello che ti ho scritto?
    il codice per l'upload è IRRILEVANTE..
    devi mettere il codice che usi nella pagina per richiamarla..
    fai qualche prova prima di postare..

    questa query ti funziona?
    Codice PHP:
    $query "UPDATE tabella SET foto='" $_FILES['foto']['modifica_foto']  . "' WHERE utente ='" $_SESSION['utente'] . "'";   mysql_query($query); 
    il campo te lo riempie con il nome della foto?
    perchè quello dovrebbe essere
    $_FILES['foto']['name']

  7. #7
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    208
    sto mettendo il recordset con dreamweaver per poter poi richiamare con il simbolo del fulmine giallo, il posto dove voglio che compaia la foto

    creando il recordset con la finestra di dreamweaver

    ok alla connessione

    ok alla tabella

    ok seleziono foto

    ma su filtro foto cosa devo selezionare?

  8. #8
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    208
    su filtro ho indicato = parametro url ../public/foto_utente_thumbs/

    ordina id = ascendente

    è corretto???

  9. #9
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    208
    cmq questo è il recordset che ho inserito nella pagina dove voglio che si veda la foto

    Codice PHP:
      <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }
    }

    $colname_Recordset_foto "-1";
    if (isset(
    $_GET['../public/foto_utente_thumbs/'])) {
      
    $colname_Recordset_foto $_GET['../public/foto_utente_thumbs/'];
    }
    mysql_select_db($database_connessione_registrazione_utente$connessione_registrazione_utente);
    $query_Recordset_foto sprintf("SELECT foto FROM tabella WHERE foto = %s"GetSQLValueString($colname_Recordset_foto"text"));
    $Recordset_foto mysql_query($query_Recordset_foto$connessione_registrazione_utente) or die(mysql_error());
    $row_Recordset_foto mysql_fetch_assoc($Recordset_foto);
    $totalRows_Recordset_foto mysql_num_rows($Recordset_foto);
    ?><?php require_once('Connections/connessione_registrazione_utente.php');
    mysql_select_db("$database_connessione_registrazione_utente")or die("cannot select DB"); ?>
    e la foto la richiamo con questo:

    Codice PHP:
    <img src= "../public/foto_utente_thumbs/<?php echo $row_Recordset_foto['foto']; ?>" >
    ma mi compare sempre il rettangolo con la croce rossa al centro (cioè nn la carica)

    dove sta il problema?

  10. #10
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,591
    hai provato a stampare ALTRI campi del recordset?
    ..no perchè ti saresti accorto che non stamperebbe nulla..
    se il tuo campo id si chiama id fai così

    Codice PHP:
    <?php require_once('Connections/connessione_registrazione_utente.php'); ?> 

    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }
    }

    $colname_Recordset_foto "-1";
    if (isset(
    $_GET['id'])) {
    $colname_Recordset_foto $_GET['id'];
    }
    mysql_select_db($database_connessione_registrazione_utente$connessione_registrazione_utente);
    $query_Recordset_foto sprintf("SELECT id, fotoFROM tabella WHERE id = %s"GetSQLValueString($colname_Recordset_foto"text"));
    $Recordset_foto mysql_query($query_Recordset_foto$connessione_registrazione_utente) or die(mysql_error());
    $row_Recordset_foto mysql_fetch_assoc($Recordset_foto);
    $totalRows_Recordset_foto mysql_num_rows($Recordset_foto);
    ?>
    così dovrebbe andare.. ovviamente devi passare l'id in GET, nella forma pagina.php?id=UNNUMERO

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.