【问题标题】:how to store image in Sql Server with php如何使用 php 在 Sql Server 中存储图像
【发布时间】:2017-05-19 07:15:10
【问题描述】:

我使用 php 创建网站并尝试将图像从地址插入到 sqlserver 数据库,我使用此代码:

function prepareImageDBString($filepath)
{
    $out = 'null';
    $handle = @fopen($filepath, 'rb');
    if ($handle)
    {        $content = @fread($handle, filesize($filepath));
        $content = bin2hex($content);
        @fclose($handle);
        $out = "0x".$content;
    }
    return $out;
}


$out = prepareImageDBString('http://....com/img.jpg');

sqlsrv_query($conn,"INSERT INTO Imagess(imgtype) VALUES($out) ");

图像保存成功但不显示,我的意思是图像损坏保存 怎么做才能得救?

【问题讨论】:

标签: php html sql-server image insert


【解决方案1】:

你好,你可以用这样的方法来做到这一点:

            $imgID = mysql_insert_id();
            $newname = "$imgID.jpg";
            move_uploaded_file($_FILES['fileField']['tmp_name'],"../images/product/$newname");

【讨论】:

    猜你喜欢
    • 2011-08-02
    • 2014-08-13
    • 2013-05-02
    • 1970-01-01
    • 2011-01-26
    • 2015-04-02
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    相关资源
    最近更新 更多