472,958 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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 http://geoffsoper.co.uk/test/admin/import_test.php

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
Jul 17 '05 #1
1 3496
"Geoff Soper" <ne*********@alphaworks.co.uk> wrote in message
news:3f*********************@news.dial.pipex.com.. .
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.


After finally posting to usenet after ages of puzzling over this the answer
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
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: phpnube | last post by:
I used this php package to install on my system... (i had problems with the isapi package from php so im back to the cgi portion of PHP php-cgi.exe) PHP 5.0.0 installer - 26 July 2004 (CGI...
0
by: Matt | last post by:
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 MySQLDriverCS one but can't seem to get the...
5
by: mantrid | last post by:
Hello My web hosting company has lost my data due to the mysql software failing, it only affected those people using innoDB engine. I asked them why they didnt restore from a back up. They said...
5
tolkienarda
by: tolkienarda | last post by:
hi all i need to allow people to upload images to my site and then save them in a mysql database. i've looked at some prebuilt scripts using iframes but i don't think that will work for me. I want...
2
by: Christoph Krammer | last post by:
Hello, I try to write a python application with wx that shows images from a MySQL database. I use the following code to connect and get data when some event was triggered: dbconn =...
6
by: fpcreator2000 | last post by:
Hello everyone. I'm having problems with a page I've created that is used to insert data into a database. It uploads two files into two distinct folder, and it takes the filenames and inserts...
10
nathj
by: nathj | last post by:
Hi there, This thread is very similar to an earlier thread but I didn't want to hijack a thread. The issue is this. I have a mysql database on my local machine, I have installed the driver for...
4
by: Gary Baardman | last post by:
I am having a few problems returning records from a mySQL database using PHP. Firstly I must say I am trying to create a video album using MySQL, PHP and using pagination. My first problem is...
3
by: Hataf | last post by:
Hi! I am having a problem in displaying images from database. This the code gallery.php <?php session_start(); if(isset($_SESSION)){} //die('ERROR:'.mysql_error());
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.