image resizing within a loop won't function properlly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #1

    image resizing within a loop won't function properlly

    i have a file upload script and within it i use SimpleImage... its a image resizing function. When just used on it's on it works fine, and when i use it within a simple loop like the one below it works fine

    Code:
    <?php
    include('SimpleImage.php');
    $add= "images/test/Desert.jpg";
    
    $details = array();
    $details = getimagesize($add);
    $imgWidth = $details[0];
    if ($imgWidth > 450){
    			$image = new SimpleImage();
    			$image->load("$add");
    			$image->resize(450,350);
    			$image->save("$add"); 
    			
    	echo '<img src="'.$add .'" alt="test"/>';
    } else {
    echo $details[1].'<br/>';
    echo $details[4].'<br/>';
    echo $details[3].'<br/>';
    }
    ?>
    but when i include it into my upload script in the correct position it wont work.

    this is the original script i wrote

    Code:
    include('SimpleImage.php');
    while(list($key,$value) = each($_FILES['images']['name']))
    		{
    			if(!empty($value))
    			{
    				$filename = $value;
    					$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
    
    					$add = "upload/imgtemp/m/$random_digit/$filename";
    					$tempFLDR = "upload/imgtemp/t/$random_digit/$filename";
                           //echo $_FILES['images']['type'][$key];
    			     // echo "<br>";
    					copy($_FILES['images']['tmp_name'][$key], $add);
    					chmod("$add",0777);
    					copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
    					chmod("$tempFLDR",0777);
    			}
    $image = new SimpleImage();
    $image->load("$add");
    $image->resize(535,400);
    $image->save("$add"); 
    
    $image = new SimpleImage();
    $image->load("$tempFLDR");
    $image->resize(100,75);
    $image->save("$tempFLDR"); 
    		}
    and this is what i've changed it to... i've included the same loop as the 1st code in the post... i've placed it in the same position as the original within loops i've checked on a blank page to make sure it works but it keeps cutting the script short

    Code:
    include('SimpleImage.php');
    while(list($key,$value) = each($_FILES['images']['name']))
    		{
    			if(!empty($value))
    			{
    				$filename = $value;
    					$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
    
    					$add = "user/tmp/large/$eventID/$filename";
    					$tempFLDR = "user/tmp/av/$eventID/$filename";
                           //echo $_FILES['images']['type'][$key];
    			     // echo "<br>";
    					copy($_FILES['images']['tmp_name'][$key], $add);
    					chmod("$add",0777);
    					copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
    					chmod("$tempFLDR",0777);
    				
    			}
    			
    $details = array();
    $details = getimagesize($add);
    $detailsWidth = details[0];
    $detailsHeight = details[1];
    
    			if ($detailsWidth > $detailsHeight){
    			$image = new SimpleImage();
    			$image->load("$add");
    			$image->resize(450,350);
    			$image->save("$add"); 
    
    			$image = new SimpleImage();
    			$image->load("$tempFLDR");
    			$image->resize(100,70);
    			$image->save("$tempFLDR"); 
    			} 
    			elseif ($detailsHeight > $detailsWidth) {
    			$image = new SimpleImage();
    			$image->load("$add");
    			$image->resize(240,350);
    			$image->save("$add"); 
    
    			$image = new SimpleImage();
    			$image->load("$tempFLDR");
    			$image->resize(100,100);
    			$image->save("$tempFLDR"); 
    			}
    		}
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #2
    nevermind... my illness is taking my eyes away from me or making me a clutz... my problem was here

    Code:
    $details = array();
    $details = getimagesize($add);
    $detailsWidth = details[0];  // <--- i left the $ off the variable
    $detailsHeight = details[1]; // <--- i left the $ off the variable
    Last edited by Dormilich; May 25 '10, 09:50 AM. Reason: Please use [code] tags when posting code

    Comment

    Working...