Visualizzazione dei risultati da 1 a 7 su 7

Discussione: Inserimento immagine

  1. #1

    Inserimento immagine

    Salve,

    dal file "inserisci" inserisco campi dati del form e percorso immagine su db. L'immagine originale viene salvata correttamente nella cartella sul server e sul db viene salvato oltre al percorso corretto della cartella immagini un secondo percorso per la thumbnail che viene generata correttamente. Tuttavia, non viene salvato niente su una seconda cartella thumbs dove vorrei caricare la thumb creata. Allego codice file in questione. Grazie per suggerimenti.


    <?php
    require_once 'thumbnail.class.php';

    include ("config.inc.php");

    include ("connect.php");

    include ("funzioni.php");



    $thumbnail = new thumbnail;



    if (!empty($_REQUEST['submit']))

    {

    $tmp = $_FILES['uploaded_file']['tmp_name'];

    $org = $_FILES['uploaded_file']['name'];



    if ($tmp)

    {

    $directory = 'uploads/'; // Upload files to here.

    $prefix = 'uploaded_'; // Filename prefixes

    $directory2 = 'thumbs/';


    $image = $_FILES['uploaded_file']['name'];
    $image2 = $_FILES['uploaded_file']['name'].$smlImage;
    $percorso = "$directory";
    $percorso2 = "$directory2";

    $patch ="$percorso$image";

    $patch2 ="$percorso2$image2";

    $articolo = $_POST['articolo'];

    $descrizione = $_POST['descrizione'];

    $caratteristiche = $_POST['caratteristiche'];

    $prezzo = $_POST['prezzo'];

    $scadenza = $_POST['scadenza'];

    $datains = $_POST['datains'];






    // Upload all image files

    $lrgImage = $thumbnail->generate($tmp, $org, $directory, $prefix.'lrg', 300); // large file

    $medImage = $thumbnail->generate($tmp, $org, $directory, $prefix.'med', 200); // medium file

    $smlImage = $thumbnail->generate($tmp, $org, $directory, $prefix.'sml', 100); // small file



    if ($smlImage && $medImage && $lrgImage) // If all files are ok

    {

    $info = '

    <fieldset>

    <legend>Files uploaded successfully</legend>

    [img]'.$lrgImage.'[/img]

    [img]'.$medImage.'[/img]

    [img]'.$smlImage.'[/img]

    </fieldset>


    ';

    }

    }

    else

    {

    $info = '

    No file selected</p>';

    }

    }



    $query="INSERT INTO promo (articolo,descrizione,immagine,immagine2,caratteri stiche,prezzo,scadenza) VALUES('$articolo','$descrizione','$patch','$patch 2','$caratteristiche','$prezzo','$scadenza')";

    $result = mysql_query($query,$db);






    // HTML ?>





    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">

    <html>

    <head>

    <title></title>

    <style>

    body {

    font-size: 90%;

    font-family: Tahoma;

    }

    legend {

    font-weight: bold;

    padding: 12px;

    }

    </style>

    </head>

    <body>



    <h1>Thumbnail Generator</h1>

    <form action="" method="post" enctype="multipart/form-data">

    <fieldset>

    <legend>Upload File & Create Thumbnails</legend>

    <input type="file" name="uploaded_file">
    <p class="Stile1">

    <label>articolo


    <input type="text" name="articolo" id="articolo">
    </label>
    </p>

    <p class="Stile1">

    <label>descrizione


    <textarea name="descrizione" id="descrizione" cols="45" rows="5"></textarea>
    </label>
    </p>
    <p class="Stile1">
    <label>caratteristiche

    <textarea name="caratteristiche" id="caratteristiche" cols="45" rows="5"></textarea>
    </label>
    </p>
    <p class="Stile1">
    <label>prezzo ( Es. 3.00)

    <input name="prezzo" type="text" id="prezzo" value="€">
    </label>
    </p>
    <p class="Stile1">
    <label>data inserimento articolo

    <input name="datains" type="text" id="datains" value="<?php echo date("Y/m/d"); ?>">
    </label>
    </p>
    <p class="Stile1">
    <label>scadenza promozione articolo (inserisci una data)

    <input type="text" name="scadenza " id="scadenza ">
    </label>
    <p class="Stile1">
    <input type="submit" name="submit" value=" go " />


    </fieldset>


    </form>

    <?

    if (!empty($info))

    {

    echo $info;

    }

    ?>



    </body>

    </html>

  2. #2
    Utente di HTML.it L'avatar di r1cky`
    Registrato dal
    Feb 2007
    Messaggi
    431
    Non vedo il codice della classe thumbnail che è proprio quello che dovevi mettere

  3. #3
    Ecco il codice della classe...

    class thumbnail

    {

    var $sourceFile; // We use this file to create the thumbnail

    var $originalFilename; // We use this to get the extension of the filename

    var $destinationDirectory; // The Directory in question

    var $destinationDirectoryFilename; // The destination filename



    var $createImageFunction = '';

    var $outputImageFunction = '';



    function generate($sourceFile = "", $originalFilename = "", $destinationDirectory = "", $destinationDirectoryFilename = "", $width = -1, $height = -1)

    {

    if (!empty($sourceFile))

    $this->sourceFile = $sourceFile;



    if (!empty($originalFilename))

    $this->originalFilename = $originalFilename;



    if (!empty($destinationDirectory))

    $this->destinationDirectory = $destinationDirectory;



    if (!empty($destinationDirectoryFilename))

    $this->destinationDirectoryFilename = $destinationDirectoryFilename;



    if (!empty($width))

    $this->width = $width;



    if (!empty($height))

    $this->height = $height;



    list(, $this->extension) = explode('.', $this->originalFilename);



    switch ($this->extension)

    {

    case 'gif' :

    $createImageFunction = 'imagecreatefromgif';

    $outputImageFunction = 'imagegif';

    break;



    case 'png' :

    $createImageFunction = 'imagecreatefrompng';

    $outputImageFunction = 'imagepng';

    break;



    case 'bmp' :

    $createImageFunction = 'imagecreatefromwbmp';

    $outputImageFunction = 'imagewbmp';

    break;



    case 'jpg': case 'jpeg':

    $createImageFunction = 'imagecreatefromjpeg';

    $outputImageFunction = 'imagejpeg';

    break;



    default :

    exit("Sorry: The format '{$this->extension}' is unsuported");

    break;

    }



    $this->img = $createImageFunction($this->sourceFile);



    list($this->org_width, $this->org_height) = getimagesize($this->sourceFile);



    if ($this->height == -1)

    {

    $this->height = round($this->org_height * $this->width / $this->org_width);

    }



    if ($this->width == -1)

    {

    $this->width = round($this->org_width * $this->height / $this->org_height);

    }



    $this->xoffset = 0;

    $this->yoffset = 0;



    $this->img_new = imagecreatetruecolor($this->width, $this->height);



    if ($this->img_new)

    {

    imagecopyresampled($this->img_new, $this->img, 0, 0, $this->xoffset, $this->yoffset, $this->width, $this->height, $this->org_width, $this->org_height);



    list($this->newFilename) = explode('.', $this->destinationDirectoryFilename);



    $this->fullDestination = ($this->destinationDirectory.'/'.$this->newFilename.'.'.$this->extension);



    $outputImageFunction($this->img_new, $this->fullDestination);

    }

    else

    {

    $this->failed = true;

    }



    if ($this->failed == false)

    {

    return $this->fullDestination;

    }

    }

    }

    ?>

  4. #4

  5. #5
    Ciao,

    piccolo consiglio, è meglio postare il codice nei tag bbcode php se vuoi che qualcuno comprenda il codice che posti e quindi sia invogliato a risponderti .

    I tag bbcode php sono presenti nella casella di testo dove inserisci il testo (il bottone # a sinistra e i bottoni List e Quote a destra)
    The fastest Redis alternative ... cachegrand! https://github.com/danielealbano/cachegrand

  6. #6
    Questa e' la classe thumbnail

    Codice PHP:
        class thumbnail

        
    {

            var 
    $sourceFile// We use this file to create the thumbnail

            
    var $originalFilename// We use this to get the extension of the filename

            
    var $destinationDirectory// The Directory in question

            
    var $destinationDirectoryFilename// The destination filename

            

            
    var $createImageFunction '';

            var 
    $outputImageFunction '';

            

            function 
    generate($sourceFile ""$originalFilename ""$destinationDirectory ""$destinationDirectoryFilename ""$width = -1$height = -1)

            {

          if (!empty(
    $sourceFile))

            
    $this->sourceFile $sourceFile;

          

          if (!empty(
    $originalFilename))

            
    $this->originalFilename $originalFilename;

           

          if (!empty(
    $destinationDirectory))

            
    $this->destinationDirectory $destinationDirectory;

           

          if (!empty(
    $destinationDirectoryFilename))

            
    $this->destinationDirectoryFilename $destinationDirectoryFilename;

          

          if (!empty(
    $width))

            
    $this->width $width;

          

          if (!empty(
    $height))

            
    $this->height $height;



          list(, 
    $this->extension) = explode('.'$this->originalFilename);

                

                switch (
    $this->extension)

                {

                    case 
    'gif' :

                        
    $createImageFunction 'imagecreatefromgif';

                        
    $outputImageFunction 'imagegif';

                      break;

                    

                    case 
    'png' :

                        
    $createImageFunction 'imagecreatefrompng';

                        
    $outputImageFunction 'imagepng';

                      break;

                    

                    case 
    'bmp' :

                        
    $createImageFunction 'imagecreatefromwbmp';

                        
    $outputImageFunction 'imagewbmp';

                      break;

                    

                    case 
    'jpg': case 'jpeg':

                        
    $createImageFunction 'imagecreatefromjpeg';

                        
    $outputImageFunction 'imagejpeg';

                      break;

                    

                    default : 

                        exit(
    "Sorry: The format '{$this->extension}' is unsuported");

                      break;

                }

                

                
    $this->img  $createImageFunction($this->sourceFile);

                

                list(
    $this->org_width$this->org_height) = getimagesize($this->sourceFile);

                

                if (
    $this->height == -1)

                {

                    
    $this->height round($this->org_height $this->width $this->org_width);

                }

                

                if (
    $this->width == -1)

                {

                    
    $this->width round($this->org_width $this->height $this->org_height);

                }     

                

                
    $this->xoffset 0;

                
    $this->yoffset 0;

                

                
    $this->img_new imagecreatetruecolor($this->width$this->height);    

                

                if (
    $this->img_new)

                {

                    
    imagecopyresampled($this->img_new$this->img00$this->xoffset$this->yoffset$this->width$this->height$this->org_width$this->org_height);

                    

                    list(
    $this->newFilename) = explode('.'$this->destinationDirectoryFilename);

                    

                    
    $this->fullDestination = ($this->destinationDirectory.'/'.$this->newFilename.'.'.$this->extension);

                    

                    
    $outputImageFunction($this->img_new$this->fullDestination);

                }

                else

                {

                    
    $this->failed true;

                }

                

                if (
    $this->failed == false)

                {

                    return 
    $this->fullDestination;

                }

            }

        }

    ?> 

  7. #7
    nessun suggerimento?

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.