Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2009
    Location
    Portugal/Porto
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question loop for receive multiple upload files....

    Hi all!

    Iam trying to change this code to recieve 5 input files in order to upload and resize. I now that I must make a LOOP for it, trying and tryinh without sucess!

    Anyone can help..actualy it only receive one input..."image".

    The code:

    Code:
    <?php
    if(isset($_POST['Submit']))
    {
    $size = 80;
    $filedir = 'images/'; 
    $thumbdir = 'images/'; 
    $prefix = 'small_'; 
    $maxfile = '200000';
    $mode = '0666';
    
    $userfile_name = $_FILES['image']['name'];
    $userfile_tmp = $_FILES['image']['tmp_name'];
    $userfile_size = $_FILES['image']['size'];
    $userfile_type = $_FILES['image']['type'];
    if (isset($_FILES['image']['name'])) 
    {
    $prod_img = $filedir.$userfile_name;
    $prod_img_thumb = $thumbdir.$prefix.$userfile_name;
    move_uploaded_file($userfile_tmp, $prod_img);
    chmod ($prod_img, octdec($mode));
    $sizes = getimagesize($prod_img);
    $aspect_ratio = $sizes[0]/$sizes[1]; 
    if ($sizes[0] <= $size)
    {
    $new_width = $sizes[0];
    $new_height = $sizes[1];
    }else{
    $new_width = $size;
    $new_height = abs($new_width/$aspect_ratio);
    }
    $destimg = ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image');
    $srcimg = ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');
    ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing');
    ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
    imagedestroy($destimg);
    }
    print_r($sizes);
    echo"width new: $new_width<br>height new: $new_height";
    echo '
    	<br><a href="'.$prod_img.'">
    	<img src="'.$prod_img_thumb.'" width="'.$new_width.'" heigt="'.$new_height.'">
    	</a>';
    	}
    	else
    	{
    echo '
    	<form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">
    	<input type="file" name="image1"><p>
    	<input type="file" name="image2"><p>
    	<input type="file" name="image3"><p>
    	<input type="file" name="image4"><p>
    	<input type="file" name="image5"><p>
    	<input type="Submit" name="Submit" value="Submit">
    	</form>';
    }
    ?>

  • #2
    New Coder
    Join Date
    Sep 2009
    Location
    Portugal/Porto
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    After a while I figure how to fix it..Everithing is workink now...but when I make the upload/resize...i receive this error's...

    Warning: getimagesize(images/) [function.getimagesize]: failed to open stream: Permission denied in C:\Programas\EasyPHP 2.0b1\www\fotos\teste.php on line 26

    Warning: Division by zero in C:\Programas\EasyPHP 2.0b1\www\fotos\teste.php on line 27

    Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Programas\EasyPHP 2.0b1\www\fotos\teste.php on line 36
    Problem In Creating image

    COMPLETE CODE:

    Code:
    <?php
    if(isset($_POST['Submit']))
    {
    	$size = 90; // the thumbnail height
    	$filedir = 'images/'; // the directory for the original image
    	$thumbdir = 'images/'; // the directory for the thumbnail image
    	$prefix = 'small_'; // the prefix to be added to the original name
    	$maxfile = '800000';
    	$mode = '0666';
    	
    	$i = 1;
    	$htmlFieldName = 'image' . $i;
    	while(isset($_FILES[$htmlFieldName])){
    		
    		$userfile_name = $_FILES[$htmlFieldName]['name'];
    		$userfile_tmp = $_FILES[$htmlFieldName]['tmp_name'];
    		$userfile_size = $_FILES[$htmlFieldName]['size'];
    		$userfile_type = $_FILES[$htmlFieldName]['type'];
    		
    		if (isset($_FILES[$htmlFieldName]['name'])) 
    		{
    			$prod_img = $filedir.$userfile_name;
    			$prod_img_thumb = $thumbdir.$prefix.$userfile_name;
    			move_uploaded_file($userfile_tmp, $prod_img);
    			chmod ($prod_img, octdec($mode));
    			$sizes = getimagesize($prod_img);
    			$aspect_ratio = $sizes[1]/$sizes[0]; 
    			if ($sizes[0] <= $size)
    			{
    				$new_width = $sizes[1];
    				$new_height = $sizes[0];
    			}else{
    				$new_height = $size;
    				$new_width = abs($new_height/$aspect_ratio);
    			}
    			$destimg = ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image');
    			$srcimg = ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');
    			ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing');
    			ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
    			imagedestroy($destimg);
    		}
    			echo '
    			<br />
    			<a href="'.$prod_img.'">
    			<img src="'.$prod_img_thumb.'" width="'.$new_width.'" heigt="'.$new_height.'">
    			</a>';
    		
    		$i++;
    		$htmlFieldName = 'image' . $i;
    	}
    	}else{
    	echo '
    	<form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">
    	<input type="file" name="image1" /><br />
    	<input type="file" name="image2" /><br />
    	<input type="file" name="image3" /><br />
    	<input type="Submit" name="Submit" value="Submit">
    	</form>';
    }
    ?>
    Anyone now's what's wrong????

  • #3
    New Coder
    Join Date
    Sep 2009
    Location
    Portugal/Porto
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Anyone!!!!!..please..............


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •