Salve a tutti,

ho un problema con uno scritto per il resize delle immagini che ha sempre funzionato ma che dopo un mio recente aggiornamento ha cominciato a darmi problemi. il mio aggiornamento consiste nel tentativo con str_replace di riuscire a gestire immagini con errori del tipo: %20, spazi etc...

con il codice attuale riesco a inserire soltanto immagini png... ( i percorsi su db sono sempre corretti e le immagini originali nella cartella immagini vengono sempre caricati correttamente... il problema si presenta soltanto nel resize...)

Codice PHP:

<?php
function createThumbs$pathToImages$pathToThumbs$thumbWidth 
{
//$estensioni = array('jpg','jpeg','gif','GIF','JPG','JPEG');
  // open the directory
  
$dir = @opendir$pathToImages );
// $fname = str_replace(" ", "", $fname);
  //$fname = str_replace("%20", "", $fname);

  //$pathToImages = str_replace(" ", "", $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' || 'jpeg' || 'GIF' || 'gif' || 'JPEG' || 'JPG' || 'png' || 'PNG' || 'bmp' || 'BMP'
    {
     
// echo "Ho creato miniatura per immagine: {$fname} 
";

      // load image and get image size
      
$img = @imagecreatefromjpeg( "{$pathToImages}{$fname}" );
      
$img = @imagecreatefromgif( "{$pathToImages}{$fname}" );
      
$img = @imagecreatefrompng( "{$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 );
 //
$img = str_replace(" ", "", $img);
      // copy and resize old image into new image 
      @imagecopyresized( 
$tmp_img$img, 0, 0, 0, 0, $new_width$new_height$width$height );
 //
$tmp_img = str_replace(" ", "", $tmp_img);
  //
$fname = str_replace(" ", "", $fname);
      // save thumbnail into a file
     @imagejpeg( 
$tmp_img, "{$pathToThumbs}{$fname}" );
      @imagegif( 
$tmp_img, "{$pathToThumbs}{$fname}" );
         @imagepng( 
$tmp_img, "{$pathToThumbs}{$fname}" );
    }
  }
 
  // close the directory
  @closedir( 
$dir );
}
createThumbs("
img/","thumbs/",100);
?>