0

I want to get image width size during upload image.

Code:

for ($i = 0; $i < $number_of_files; $i++) {
    $_FILES['file']['name'] = $files['file']['name'][$i];
    $_FILES['file']['type'] = $files['file']['type'][$i];
    $_FILES['file']['tmp_name'] = $files['file']['tmp_name'][$i];
    $_FILES['file']['error'] = $files['file']['error'][$i];
    $_FILES['file']['size'] = $files['file']['size'][$i];
    $_FILES['file']['image_width'] = $files['file']['image_width'][$i];

    $this->image_lib->initialize($config);
    $this->image_lib->watermark();

    if (!$this->image_lib->watermark()) {
        echo $this->image_lib->display_errors();
}

But when i print

print_r($_FILES['file']);

It show like this

Array
(
    [name] => 01.jpg
    [type] => image/jpeg
    [tmp_name] => /Applications/XAMPP/xamppfiles/temp/phpmbI84M
    [error] => 0
    [size] => 748459
    [image_width] => 
)

No Image Width showing.

how to do this ?

Ivan
  • 2,463
  • 1
  • 20
  • 28
Manish Tiwari
  • 1,806
  • 10
  • 42
  • 65

1 Answers1

1

You can use the following :-

$file = $_FILES["file"]['tmp_name'];
list($width, $height) = getimagesize($file);

if($width > "180" || $height > "70") { // You can add your logic
    echo "Error : image size must be 180 x 70 pixels.";
    exit;
}

It may help you.

Harsh Sanghani
  • 1,666
  • 1
  • 14
  • 32