【问题标题】:Warning: Illegal string offset 'mime'警告:非法字符串偏移 'mime'
【发布时间】:2017-02-25 04:27:27
【问题描述】:

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

非法偏移'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();
}
?>

如何解决?

【问题讨论】:

标签: php mysql


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-09-30
    • 2013-09-13
    • 2013-04-11
    • 2012-04-09
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多