Visualizzazione dei risultati da 1 a 6 su 6

Discussione: codice non funzionante

  1. #1
    Utente di HTML.it L'avatar di crisal
    Registrato dal
    Oct 2001
    Messaggi
    45

    codice non funzionante

    ciao a tutti ho questo codice per creare dei thumbnails ma non mi funziona si blocca al primo echo qualcuno sa dirmi dov'e' l'errore?


    <?php
    function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
    {
    // open the directory
    $dir = opendir( $pathToImages );

    // loop through it, looking for any/all JPG files:
    while (false !== ($fname = readdir( $dir ))) {
    // parse path for the extension
    $info = pathinfo($pathToImages . $fname);
    // continue only if this is a JPEG image
    if ( strtolower($info['extension']) == 'jpg' )
    {
    echo "Creating thumbnail for $fname
    "; //<===qui e' dove si ferma???????

    // load image and get image size
    $img = imagecreatefromjpeg( "$pathToImages/$fname" );
    $width = imagesx( $img );
    $height = imagesy( $img );

    // calculate thumbnail size
    $new_width = $thumbWidth;
    $new_height = floor( $height * ( $thumbWidth / $width ) );

    // create a new temporary image
    $tmp_img = imagecreatetruecolor( $new_width, $new_height );

    // copy and resize old image into new image
    imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

    // save thumbnail into a file
    imagejpeg( $tmp_img, "$pathToThumbs/$fname" );
    }
    }
    // close the directory
    closedir( $dir );
    }
    // call createThumb function and pass to it as parameters the path
    // to the directory that contains images, the path to the directory
    // in which thumbnails will be placed and the thumbnail's width.
    // We are assuming that the path will be a relative path working
    // both in the filesystem, and through the web for links
    createThumbs("photo/","photo/thumbs/",100);

    function createGallery( $pathToImages, $pathToThumbs )
    {
    echo "Creating photo_fulvio.html
    ";

    $output = "<html>";
    $output .= "<head><title>PHOTO_FULVIO</title></head>";
    $output .= "<body>";
    $output .= "<table cellspacing=\"0\" cellpadding=\"2\" width=\"500\">";
    $output .= "<tr>";

    // open the directory
    $dir = opendir( $pathToThumbs );

    $counter = 0;
    // loop through the directory
    while (false !== ($fname = readdir($dir)))
    {
    // strip the . and .. entries out
    if ($fname != '.' && $fname != '..')
    {
    $output .= "<td valign=\"middle\" align=\"center\"><a href=\"/$pathToImages/$fname\">";
    $output .= "<img src=\"$pathToThumbs/$fname\" border=\"0\" />";
    $output .= "</a></td>";

    $counter += 1;
    if ( $counter % 4 == 0 ) { $output .= "</tr><tr>"; }
    }
    }
    // close the directory
    closedir( $dir );

    $output .= "</tr>";
    $output .= "</table>";
    $output .= "</body>";
    $output .= "</html>";

    // open the file
    $fhandle = fopen( "photo_fulvio.html", "w" );
    // write the contents of the $output variable to the file
    fwrite( $fhandle, $output );
    // close the file
    fclose( $fhandle );
    }
    // call createGallery function and pass to it as parameters the path
    // to the directory that contains images and the path to the directory
    // in which thumbnails will be placed. We are assuming that
    // the path will be a relative path working
    // both in the filesystem, and through the web for links
    createGallery("fulvio/","fulvio/thumbs/");
    ?>

  2. #2
    che errore ti da?

  3. #3
    Utente di HTML.it L'avatar di crisal
    Registrato dal
    Oct 2001
    Messaggi
    45
    non mi da nessun errore semplicemente si ferma al primo echo "echo "Creating thumbnail for $fname
    ";"e poi non fa piu' niente non crea i files che dovrebbe e non mi crea la pagina di ritorno che dovrebbe essere "photo_fulvio.html"

  4. #4
    Utente di HTML.it L'avatar di jeppox
    Registrato dal
    Mar 2007
    Messaggi
    436
    hai provato così?

    Codice PHP:
    echo "Creating thumbnail for ".$fname."
    "

    commenta il tuo codice con i tag PHP.

  5. #5
    a prima vista sembra tutto corretto, ma se si blocca così sui due piedi di solito è che c'è qualche errore di sintassi..cmq controllo per bene...

  6. #6
    Utente di HTML.it L'avatar di crisal
    Registrato dal
    Oct 2001
    Messaggi
    45
    niente sempre lo stesso

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.