I am doing an image upload handler and I would like it to detect the dimensions of the image that's been uploaded by the user.
So I start with:
if (isset($_FILES['image'])) etc....
and I have
list($width, $height) = getimagesize(...);
How am i supposed to use them together?
Thanks a lot
The getimagesize() function will determine the size of any supported given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondent HTTP content type.
$imgsize=filesize("http://localhost/projects/site/schwe/user/1/1.jpg");
PHP Code to Validate and Upload Image File In PHP, we validate the file type, size and dimension before uploading. The uploaded file data like name size, temporary target are in $_FILES[“image_file”] array. PHP move_uploaded_file function is used to upload the file by accessing file data stored in $_FILES superglobal.
php $file_size = filesize($_SERVER['DOCUMENT_ROOT']. "/Advertisers/2564. jpg"); // Get file size in bytes $file_size = $file_size / 1024; // Get file size in KB echo $file_size; // Echo file size ?>
You can do this as such
$filename = $_FILES['image']['tmp_name'];
$size = getimagesize($filename);
// or
list($width, $height) = getimagesize($filename);
// USAGE: echo $width; echo $height;
Using the condition combined, here is an example
if (isset($_FILES['image'])) {
$filename = $_FILES['image']['tmp_name'];
list($width, $height) = getimagesize($filename);
echo $width;
echo $height;
}
Try this for multi images :
for($i=0; $i < count($filenames); $i++){
$image_info = getimagesize($images['tmp_name'][$i]);
$image_width = $image_info[0];
$image_height = $image_info[1];
}
Try this for single image :
$image_info = getimagesize($images['tmp_name']);
$image_width = $image_info[0];
$image_height = $image_info[1];
at least it works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With