Visualizzazione dei risultati da 1 a 2 su 2

Discussione: problema multi upload

  1. #1

    problema multi upload

    ciao a tutti!
    ho un piccolo problema col mio multi upload, ho una funzione che mi ridimensiona le immagini che si chiama make_thumb() ma quando invio i file da form mi da questo errore:

    Fatal error: Cannot redeclare make_thumb() (previously declared in d:\www\MW_qPPqcynGq\artesapori.com\multiupload\pro va.php:23) in d:\www\MW_qPPqcynGq\artesapori.com\multiupload\pro va.php on line 23


    forse perchè è un upload multiplo? perchè se faccio l'up di 1 file me lo prende bene...
    lo script finale è questo se avete pazienza:

    codice:
    <?php
    
    
    $uploadNeed = $_POST['uploadNeed'];
    
    for($x=0; $x<$uploadNeed; $x++){
    
    $image = $_FILES['uploadFile'.$x]['name'];
    echo $_FILES['uploadFile'.$x]['name']." eccolo - ";
    //define a maxim size for the uploaded images
    
    define ("MAX_SIZE","1200");
    
    define ("WIDTH","40");
    define ("HEIGHT","40");
    
    
    // this is the function that will create the thumbnail image from the uploaded image
    // the resize will be done considering the width and height defined, but without deforming the image
    
    ###### Inizio la funzione per il resize delle foto -----------------------------------------------------------
    
    function make_thumb($img_name,$filename,$new_w,$new_h)
    {
    //get image extension.
    $ext=getExtension($img_name);
    //creates the new image using the appropriate function from gd library
    if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
    $src_img=imagecreatefromjpeg($img_name);
    
    if(!strcmp("png",$ext))
    $src_img=imagecreatefrompng($img_name);
    
    //gets the dimmensions of the image
    $old_x=imageSX($src_img);
    $old_y=imageSY($src_img);
    
    $ratio1=$old_x/$new_w;
    $ratio2=$old_y/$new_h;
    if($ratio1>$ratio2) {
    $thumb_w=$new_w;
    $thumb_h=$old_y/$ratio1;
    }
    else {
    $thumb_h=$new_h;
    $thumb_w=$old_x/$ratio2;
    }
    
    // we create a new image with the new dimmensions
    $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
    
    // resize the big image to the new created one
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
    
    
    if(!strcmp("png",$ext))
    imagepng($dst_img,$filename);
    else
    imagejpeg($dst_img,$filename);
    
    
    imagedestroy($dst_img);
    imagedestroy($src_img);
    }
    
    function getExtension($str) {
    	$i = strrpos($str,".");
    	if (!$i) { return ""; }
    	$l = strlen($str) - $i;
    	$ext = substr($str,$i+1,$l);
    	return $ext;
    }
    
    $errors=0;
    
    
    	if ($image){ 
    
    		$filename = stripslashes($_FILES['uploadFile'.$x]['name']);
    
    		$extension = getExtension($filename);
    		$extension = strtolower($extension);
    
    		if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")){
    
    				//echo 'non è valido il tipo di immagine!';
    
    				$errors = 1;
    
    			}else{
    
    		$size = getimagesize($_FILES['uploadFile'.$x]['tmp_name']);
    		$sizekb = filesize($_FILES['uploadFile'.$x]['tmp_name']);
    
    		//if ($sizekb > MAX_SIZE*1024){
    
    			//echo 'immagine troppo grande!';
    			//$errors = 1;
    
    	//	}
    
    
    		$image_name = time().'.'.$extension;
    
    # Foto grandi -----------------------------------------------
    		$newname = "../public/foto_viaggio/".$image_name;
    
    		$copied = copy($_FILES['uploadFile'.$x]['tmp_name'], $newname);
    //echo $newname;
    			if (!$copied){
    
    			//echo 'foto inserita con successo!';
    			
    			$errors = 1;
    
    			}else{
    
    			// the new thumbnail image will be placed in images/thumbs/ folder
    # Thumbnails -----------------------------------------------------------------------
    			$thumb_name = '../public/thumbs/thumb_'.$image_name;
    
    			$thumb = make_thumb($newname, $thumb_name, 350, 350);
    
    			}
    		}
    	}
    	echo "(".$x.")";
    }
    
    
    //If no errors registred, print the success message and show the thumbnail image created
    
    	//echo '[img]'.$thumb_name.'[/img]';
    
    
    
    //}
    
    # end loop
    
    
    ?>

    grazie mille!

  2. #2
    Non è che stai includendo lo stesso file due volte?
    In ogni caso NON dovresti usare copy() ma move_uploaded_file()

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.