Iceman512 Posted August 15, 2007 Share Posted August 15, 2007 Hi everyone! Obviously, I'm a total idiot with arrays. Can someone please tell me why I get the following errors: Warning: chmod() [function.chmod]: No such file or directory in /home/sites/servertestbed.co.uk/public_html/admin/image_new.php on line 113 Warning: getimagesize(../downloads/images/Array) [function.getimagesize]: failed to open stream: No such file or directory in /home/sites/servertestbed.co.uk/public_html/admin/image_new.php on line 115 Warning: Division by zero in /home/sites/servertestbed.co.uk/public_html/admin/image_new.php on line 116 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/sites/servertestbed.co.uk/public_html/admin/image_new.php on line 127 Problem In Creating image when running this code: <?php while(list($key,$value) = each($_FILES[image][name])) { if(!empty($value)){ $size = 144; // the thumbnail height $filedir = '../images/'; // the directory for the original image $thumbdir = '../thumbs/'; // the directory for the thumbnail image $prefix = 'tn_'; // the prefix to be added to the original name $maxfile = '2048000'; // 2MB $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[1] <= $size) { $new_height = $sizes[0]; $new_width = $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'); ImageCopyResampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); ImageJPEG($destimg,$prod_img_thumb,75) or die('Problem In saving'); imagedestroy($destimg); } echo '<p style="vertical-align:center;"><a href="'.$prod_img.'" target="_blank"> <img src="'.$prod_img_thumb.'" width="'.$new_width.'" height="'.$new_height.'" border="0"> </a> Image uploaded successfully!</p><br />'; } elseif (empty($value)) { echo 'Input field was empty<br />'; } } ?> Here is the form used to submit the images/files: <?php $max_img = 5; // Number of upload fields echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">'; for($i=1; $i<=$max_img; $i++) { echo 'Image '.$i.' <input type="file" name="image[]" size="45" class="bginput" /><br />'; } echo '<input style="padding:2px 5px;" type="submit" name="newImage" value=" Upload " />'; echo '</form>'; }?> Thank you for any help! Regards, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/65019-confusion-with-image-arrays/ Share on other sites More sharing options...
Orio Posted August 15, 2007 Share Posted August 15, 2007 Change this part: <?php $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'])) ?> With: <?php $userfile_name = $_FILES['image']['name'][$key]; $userfile_tmp = $_FILES['image']['tmp_name'][$key]; $userfile_size = $_FILES['image']['size'][$key]; $userfile_type = $_FILES['image']['type'][$key]; if (isset($_FILES['image']['name'][$key])) ?> I think that should do. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/65019-confusion-with-image-arrays/#findComment-324503 Share on other sites More sharing options...
Iceman512 Posted August 15, 2007 Author Share Posted August 15, 2007 Hi! Problem solved - that worked perfectly!! Thank u very much Orio and everyone else for looking. Regards, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/65019-confusion-with-image-arrays/#findComment-324556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.