Jump to content

[SOLVED] getimagesize


chocopi

Recommended Posts

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 ;D

 

~ Chocopi

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.