使用未定义常量 IMAGETYPE_WEBP - 假设 'IMAGETYPE_WEBP'
Use of undefined constant IMAGETYPE_WEBP - assumed 'IMAGETYPE_WEBP'
我的 PHP 5.6.3 版本并检查 PHP.INI 我的 php 支持并接受 WEBP 图像文件
一直报错
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
我的 php 支持并接受 WEBP 文件,甚至可以显示 WEBP 图像。
<?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";
}
}?>
我不知道如何通过这种 WEBP 图像类型。
感谢任何帮助
来自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)
所以这只是 - 从 PHP 7.1.0
开始可用
我在 PHP 7.0.0
中出现同样的错误
解决方法:
if(!defined('IMAGETYPE_WEBP')){
define('IMAGETYPE_WEBP', 18);
}
我的 PHP 5.6.3 版本并检查 PHP.INI 我的 php 支持并接受 WEBP 图像文件
一直报错
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
我的 php 支持并接受 WEBP 文件,甚至可以显示 WEBP 图像。
<?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";
}
}?>
我不知道如何通过这种 WEBP 图像类型。
感谢任何帮助
来自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)
所以这只是 - 从 PHP 7.1.0
开始可用我在 PHP 7.0.0
中出现同样的错误解决方法:
if(!defined('IMAGETYPE_WEBP')){
define('IMAGETYPE_WEBP', 18);
}