chocopi Posted July 2, 2007 Share Posted July 2, 2007 How do you actually get the dimensions of an image using getimagesize(). I do not know which variable I should be using. Here is my code <html> <body> <br /> <center> <form name="upload" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data"> <input type="file" name="avatar" id="avatar" maxlength="60" /> <br /> <input type="submit" name="submit" id="submit" value="Upload" /> <br /> </form> <?php if($_POST) { // set variables $errors = 0; $directory = 'files/'; $max_file_size = '10000'; $allowed_files = array('image/gif'); $file_location = 'avatar/'; $file_upload_name = ''.$page_id.''; // get avatar information $file_name = $_FILES['avatar']['name']; $file_size = $_FILES['avatar']['size']; $file_type = $_FILES['avatar']['type']; $file_dim = getimagesize(???); // what goes here ? echo "name = ".$file_name."<br />"; echo "size = ".$file_size."<br />"; echo "type = ".$file_type."<br />"; echo "dim = ".$file_dim."<br />"; if(empty($file_size) or empty($file_name) or empty($file_type)) { } else { list($blank,$file_extension) = explode('image/',$file_type); if($file_size > $max_file_size) { echo "Your file is larger than 10kb.<br />"; $errors++; } if(!in_array($file_type, $allowed_files)) { echo "You are not allowed to upload that file type.<br />You are only allowed: .gif<br />"; $errors++; } if($errors == 0) { copy($_FILES['avatar']['tmp_name'], "files/".$_FILES['avatar']['name']) or die ("Could not copy"); echo "Your image has been uploaded"; } else if($errors > 0) { $errors = 0; die(""); } } } ?> </body> </html> Cheers ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/58047-solved-getimagesize/ Share on other sites More sharing options...
HuggieBear Posted July 2, 2007 Share Posted July 2, 2007 Try the following: <?php // Get the details of the image list($width, $height, $type, $html_string, $mime) = getimagesize($_FILES['avatar']['tmp_name']); // Print out the width and height echo "Width: $width<br>\n"; echo "Height: $height<br>\n"; ?> Or alternatively, get all the information and list it like so <?php // Get the details of the image $image_details = getimagesize($_FILES['avatar']['tmp_name']); // Print out all information foreach ($image_details as $v){ echo "$v<br>\n"; } ?> This will be ordered as follows... Width, Height, type of image, html string to use in <img> tags, mime type. But I prefer the first method. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/58047-solved-getimagesize/#findComment-287803 Share on other sites More sharing options...
chocopi Posted July 2, 2007 Author Share Posted July 2, 2007 Cheers, Huggie Quote Link to comment https://forums.phpfreaks.com/topic/58047-solved-getimagesize/#findComment-287819 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.