[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 502
  • Last Modified:

Problem viewing mssql image field from php

Greetings experts,
Long time ago I had a question about how to extract / view image field in mssql using php and thanks for BenMorel who gave me the correct codes.
The code is like this :-

<?php
// change to suit your needs
$tempFolder = '/tmp/';
mssql_connect('server','username','password') or die('error connecting to db server');
mssql_select_db('database') or die('error selecting db');

// load photo
$query = "select photo from photograph limit 1";
$res = mssql_query($query) or die('error querying');
$row = mssql_fetch_assoc($res);
mssql_free_result($res);

// write temporary file for getimagesize()
$tempFile = $tempFolder . '/' . md5(uniqid(rand()));
$fp = fopen($tempFile, 'wb') or die('Error writing temp file');
fwrite($fp, $row['photo']) or die('error writing');
fclose($fp);

// get infos from image file
$info = getimagesize($tempFile);

// delete temp file
unlink($tempFile) or die('error deleting');

// send to browser
header('Content-Type: ' . $info['mime']);
print($row['photo']);
?>


This used to work fine and it was showing the complete picture .. lately I checked the code again and strangely it started showing a small part of the picture ( like if there is a picture of a complete head it would show only the head up to eyes part ) .. maybe they changed the picture type that they used to store in the image field ?
How can I tell the above code to show the complete image field regardless to its type or its size ?
Greatful if you can help.
Note: - I posed this message earlier but no one suggested any solutions.
Regards
0
npiut
Asked:
npiut
2 Solutions
 
Richard QuadlingSenior Software DeverloperCommented:
Is it possible to NOT delete the images? If so, stop deleting for a while and check the size.

Are they all the same size?

If so, then the sysops may have set limits to the amount of data being read in 1 hit.

If you run ...

<?php phpinfo(); ?>

are there any sizes related to the filesize? Is there any limits on memory defined (normally a -1 means unlimited).
0
 
cristi_2112Commented:
You can use this code to see if the temp file looks ok:
<?php
// change to suit your needs
$tempFolder = '/tmp/';
mssql_connect('server','username','password') or die('error connecting to db server');
mssql_select_db('database') or die('error selecting db');

// load photo
$query = "select photo from photograph limit 1";
$res = mssql_query($query) or die('error querying');
$row = mssql_fetch_assoc($res);
mssql_free_result($res);

// write temporary file for getimagesize()
$tempFile = $tempFolder . '/' . md5(uniqid(rand()));
$fp = fopen($tempFile, 'wb') or die('Error writing temp file');
fwrite($fp, $row['photo']) or die('error writing');
fclose($fp);

echo '<img src="' . $tempFile . '"/>';

/*
// get infos from image file
$info = getimagesize($tempFile);

// delete temp file
unlink($tempFile) or die('error deleting');

// send to browser
header('Content-Type: ' . $info['mime']);
print($row['photo']);*/
?>

If the image looks ok, then there is definitely something wrong with your GD extension; thus getimagesize() is not working well.
If the image doesn't look ok (and I think it won't), your fields in the database are corrupted. You have to make sure you're using proper fields-types.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now