473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 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 3514
"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());
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.