0

my version of PHP 5.6.3 and checked in PHP.INI that my php supports and accepts WEBP image files

It is constantly giving error.

Notice: Use of undefined constant IMAGETYPE_WEBP - assumed 'IMAGETYPE_WEBP' in C:\xampp\htdocs\dubai\xfiles1.php on line 19

Warning: image_type_to_mime_type() expects parameter 1 to be long, string given in C:\xampp\htdocs\dubai\xfiles1.php on line 19

my php supports and accepts WEBP files and even display the WEBP images.

<?php
if (isset($_POST["csubmit"])) {

$_POST["property_title"] = str_replace(' ','-','meraki developers dubai Arjan 2bhk apartment');
$_POST["property_type"] = '2bhk';


// image mime to be checked against
$imagetype = array(image_type_to_mime_type(IMAGETYPE_GIF), image_type_to_mime_type(IMAGETYPE_JPEG),
    image_type_to_mime_type(IMAGETYPE_PNG),image_type_to_mime_type(IMAGETYPE_WEBP));

$error_msg = "";
$imageUploadERROR = FALSE;
$FOLDER = "uploads/";
$myfile = $_FILES["property_images"];

for ($i = 0; $i < count($myfile["name"]); $i++) {

    if ($myfile["name"][$i] <> "" && $myfile["error"][$i] == 0) {
        // uploaded file is OK

        if (in_array($myfile["type"][$i], $imagetype)) {
            // get the extention of the file
            $file_extention = @strtolower(@end(@explode(".", $myfile["name"][$i])));
            // Setting an unique name for the file
            $file_name = $_POST["property_title"] . '-' . date("Ymd") . '_' . rand(10000, 990000) . '.' . $file_extention;

            if (move_uploaded_file($myfile["tmp_name"][$i], $FOLDER . $file_name) === FALSE) {
                $error_msg = "Error while uploading the file";
            } else {
                $error_msg = "File uploaded successfully with name: " . $file_name;

                $location = 'uploads/' . $file_name;

                mysqli_query($con,"insert into photo (location) values ('$location')");


            }
        } else {
            $error_msg = "File is not a valid image type.";
        }
    }

    if ($imageUploadERROR) {
        // if upload error break the loop and display the error
        break;
    }
}

if ($imageUploadERROR === FALSE) {
    // Failed to upload file, you can write your code here
    echo $error_msg;
} else {
    // file is uploaded, you can write your code here
    echo "All file is uploaded successfully";
}
}?>

I dont know how to get thru this WEBP imagetype.

Any help is appreciated

bbidadi
  • 85
  • 12

2 Answers2

3

From the manual...

IMAGETYPE_WEBP (integer)

Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. (Available as of PHP 7.1.0)

So this is only - Available as of PHP 7.1.0

Community
  • 1
  • 1
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
1

Same error for my in PHP 7.0.0

Solved with:

if(!defined('IMAGETYPE_WEBP')){
    define('IMAGETYPE_WEBP', 18);
}
MTK
  • 3,300
  • 2
  • 33
  • 49