Ask a Question related to PHP Development, Design and Development.
-
Geoff Soper #1
Problems with images in MySQL database
I'm having problem with images becoming corrupted after loading them into a
MySQL database and extracting them again. I'm pretty sure it's todo with
escaping slashes but I'm at a loss as to how to confirm this and find a
solution.
A piece of test code is below, the import script displays the image before
it goes in and then uses a second script to display it straight from the
database as well as extracting it to a file and displaying that. It's
scruffy as it's stripped from a larger system but it works (or more
accurately breaks!) Imagemagick is used for the scaling operation.
The script can be seen at [url]http://geoffsoper.co.uk/test/admin/import_test.php[/url]
Some configuration settings that may be relevant are:
Local Master
magic_quotes_gpc Off On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
Please ask if you need to know any other PHP configuration settings.
I'd be very grateful for any clues as to what is going on.
Many thanks,
Geoff
<?php
$new_display_size = 640;
include('xxxxxxxx/test.cfg');
if ($config_file_included != true)
{
die('Configuration file not found.');
}
include($admin_inc_dir . 'db.inc');
include($admin_inc_dir . 'misc.inc');
/* Connecting, selecting database */
$link = mysql_connect($db_host, $db_user, $db_password)
or die("Could not connect : " . mysql_error());
mysql_select_db($db_database) or die("Could not select database");
$input_path = "xxxxxxxxx/039_35a.jpg";
$display_path = "xxxxxxxxx/display.jpg";
$output_path = "xxxxxxxxx/output.jpg";
echo "convert -sample 640x427 $input_path $display_path<br>";
exec ("convert -sample 640x427 $input_path $display_path");
echo"Original:<br><img
src=\"http://geoffsoper.co.uk/test/upload/039_35a.jpg\"><br>";
echo"Imagemagick raw:<br><img
src=\"http://geoffsoper.co.uk/test/upload/test/raw.jpg\"><br>";
$display_s = filesize($display_path);
$display_handle = fopen($display_path, "r");
$display_content = fread($display_handle, $display_s);
$display_content = addslashes($display_content);
$sql = "INSERT INTO `t_photos` (`type`, `display_content`) ";
$sql .= "VALUES ('image/jpeg', '$display_content');";
// echo "sql = $sql<br>";
db_query($sql, __LINE__, __FILE__);
$id = mysql_insert_id($link);
echo"Database: <br><img src=\"get_photo_test.php?id=$id\"><br>";
$sql = "SELECT `display_content`";
$sql .= "FROM `t_photos` ";
$sql .= "WHERE `id` = $id";
$photo_result = db_query($sql, __LINE__, __FILE__);
$photo_row = mysql_fetch_assoc($photo_result);
//extract raw from database save as id
$handle = fopen($output_path, 'w');
fwrite($handle, $photo_row['display_content']);
fclose($handle);
echo"Database -> file: <br><img
src=\"http://geoffsoper.co.uk/test/upload/output.jpg\"><br>";
?>
<?php
include('xxxxxxx/test.cfg');
if ($config_file_included != true)
{
die('Configuration file not found.');
}
include($admin_inc_dir . 'db.inc');
// Connecting, selecting database
db_start($db_host, $db_user, $db_password, $db_database);
$sql = "SELECT type, display_content as output ";
$sql .= "FROM t_photos ";
$sql .= "WHERE id = {$_REQUEST['id']}";
$result = db_query($sql, __LINE__, __FILE__);
if(mysql_num_rows($result) == 1)
{
$fileType = @mysql_result($result, 0, "type");
$fileContent = @mysql_result($result, 0, "output");
}
else
{
echo "Record doesn't exist.";
}
$img = imagecreatefromstring($fileContent);
imagejpeg($img);
?>
--
Remove nospam in email address to reply
Geoff Soper Guest
-
MySQL Database not retrieving the full database
Hi, I am using MySQL and PHP for my repository. It has 500+ records. till now it was displayiing all records in the database, but since from one... -
Images and mysql
Hi all, I was wondering If anyone knows how to insert images into MySQL and how to retrieve and display the images... VIA php. Thanks -
Displaying Images from the Mysql Database
Hi! everyone, i need help with displaying the images from the database. I successfully inserted an image to mysql database by converting it to... -
Displaying images from a MySQL Database
Hi I'm have difficulty displaying images that are stored in a MySQL database. I've tried using the odbc.net provider, the ByteFX provider and the... -
Images from MySQL
Hi All I'm trying to store images in a MYSQL db, the images at being uploaded for an external program in a blob field. I have had a look round... -
Geoff Soper #2
Re: Problems with images in MySQL database
"Geoff Soper" <news.nospam@alphaworks.co.uk> wrote in message
news:3fa3ee39$0$250$cc9e4d1f@news.dial.pipex.com.. .a> I'm having problem with images becoming corrupted after loading them intoAfter finally posting to usenet after ages of puzzling over this the answer> MySQL database and extracting them again. I'm pretty sure it's todo with
> escaping slashes but I'm at a loss as to how to confirm this and find a
> solution.
>
> A piece of test code is below, the import script displays the image before
> it goes in and then uses a second script to display it straight from the
> database as well as extracting it to a file and displaying that. It's
> scruffy as it's stripped from a larger system but it works (or more
> accurately breaks!) Imagemagick is used for the scaling operation.
>
strikes me! I was using a BLOB which has a size limit of 64k! Now I've
changed to a MEDIUMBLOB all is OK!
Sorry,
Geoff
--
Remove nospam in email address to reply
Geoff Soper Guest



Reply With Quote

