1

私は、読み取りアクセスしかできないサードパーティ サーバー (MS SQLSRV) からのデータを使用するアプリケーションに取り組んでいます。

そのサーバー上の画像は IMAGE データ型として保存されます。AngularJS フロントエンドのバックエンドとして php (Laravel 5) を使用して画像を表示しています。進め方がわからない。

$students = DB::table('StudentImage')->where('STUDENTID', $id)->get();
$image = imagecreatefromstring($students[0]->IMAGE1); // unrecognized format error

私もこれを試しました:

$db = new PDO(...);
$stmt = $db->prepare("select IMAGE1 from [StudentImage] where [STUDENTID] = ?");
$stmt->execute([$id]);
$stmt->bindColumn('IMAGE1', $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);

return response($lob, 200, ['Content-Type'=>'image/jpg']);

私が得るのは20x20の空白の画像だけです。しかし、Navicat (DB 管理ツール) で画像を見ることができます。

続行するにはどうすればよいですか?

4

1 に答える 1

0

After a lot of head banging, I've figured this out. Turns out there's a default size limit for "text" fields in SQL Server. All you have to do is "reset" the size before running the SELECT query, using the SET TEXTSIZE command:

<?php

    DB::select('SET TEXTSIZE 10485760');

    $students = DB::table('StudentImage')->where('STUDENTID', $id)->get();
    $image = imagecreatefromstring($students[0]->IMAGE1);

?>

This will set the max size to 10 MB, which should be enough to display the image you'd like. This is probably what Navicat presets before running a query.

于 2016-01-12T19:48:03.023 に答える