gpt4 book ai didi

php - 警告 : Illegal string offset 'mime'

转载 作者:行者123 更新时间:2023-11-29 07:03:54 27 4
gpt4 key购买 nike

我尝试在 MySQL 中存储图像并收到警告

Illegal offset 'mime'

在以下代码上:

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = mysql_connect("localhost","root","");
$db = mysql_select_db("imagestore",$conn);
if(!$db)
{
echo mysql_error();
}
$rollNo = $_POST['rollNo'];
$image = addslashes (file_get_contents($_FILES['image']['tmp_name']));
$image_s=getimagesize($_FILES['image']['tmp_name']);
$imgtype = $image['mime'];
$q = "INSERT INTO students VALUES('','$rollNo','$image','$imgtype')";
$r=mysql_query($q,$conn);
if($r)
{
echo "Information stored successfully";
}
else
{
echo mysql_error();
}
?>

如何解决?

最佳答案

错字。获取 mime 信息时您使用了错误的变量名称。将 $image[mime] 替换为 $image_s; getimagesize() 提供 mime 信息。

$image_s = getimagesize($_FILES['image']['tmp_name']);
$imgtype = $image_s['mime'];

关于php - 警告 : Illegal string offset 'mime' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42451952/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com