Entry
Database: MySql: PHPRunner: Image: Upload: How to upload images in your database with PHPRunner?
May 17th, 2005 08:39
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 14 April 2021 - 03:07 pm ----------------------
Database: MySql: PHPRunner: Image: Upload: How to upload images in
your database with PHPRunner?
---
Steps: Overview:
1. -First create that table in MySql
1. -Start MySql
2. -Create a database
e.g.
CREATE DATABASE database1;
3. -Open that database
USE database1;
4. -Create a table
1. -Create a BLOB field in your database to store the image
(in that column the binary data of the image are stored)
2. -Possibly add a field to your database table to add the
filename (in that column the filename is stored)
e.g.
--- cut here: begin --------------------------------------------------
CREATE TABLE `table1` (
`Photo` BLOB NOT NULL,
`PhotoFilename` VARCHAR(100) NOT NULL DEFAULT '',
);
--- cut here: end ----------------------------------------------------
2. -Start PHPRunner
3. -Connect to MySql
4. -Select from list the database containing this table
e.g.
database1
5. -Select by highlighting and enabling the checkbox this table
containing this imagefield(s)
e.g.
table1
6. -In the step screen 'Formatting' in PHPRunner set the
1. -column 'View as' to 'Database image'
1. -Select from list 'View format'
1. -To change the (fixed) size of the
picture as it will be shown
in your browser afterwards
click on 'Change...'
1. -Fill in 'Column width'
2. -Image height (e.g. 100)
3. -Image width (e.g. 100)
2. column 'Edit as' to 'Database file'
1. -Select from list 'Edit format'
1. -Click on 'Change...'
1. -Select the column name
in which you store your
filename in your table
e.g.
PhotoFilename
7. -Show the result in your webbrowser
1. -After you built your project
in PHPRunner
1. Click the button 'View in browser'
or type the URL of your
project in your browser
e.g.
http://localhost/mydatabase/index.htm
2. Login to your project
3. Select the table which
contains your pictures
e.g.
table1
4. Click on the 'Edit' link
1. Click the 'Browse...'
button
2. -Enable radio button 'Update'
3. Navigate to the directory
containing the image you
want to upload
e.g.
c:\temp\mypicturefilename.jpg
1. -Click button 'Open'
4. -Click button 'Save'
to save this record
5. If you now go back to the
table (click e.g. 'back to list')
you should see the picture
displayed in your browser
===
Note:
What you thus basically do here is storing the
whole picture in binary format physically in your
MySql database.
---
Thus when that MySql database runs on another computer (e.g. of your
Internet provider), when you upload your picture, it is really stored
physically (in binary format) in that database on that computer. Thus
if you have access to that computer from elsewhere, you can see that
picture(s) basically on every computer (in the world) with (Internet)
access to that computer.
---
So you really need to have a field for it in your database, in which to
put that.
---
That field has to be of the BLOB
(='B'inary 'L'arge 'OB'ject) type which allows
images of up to 65536 bytes.
---
Otherwise use MEDIUMBLOB,
or even LARGEBLOB.
---
-The maximum filesize for a
BLOB field is 65536 (=2^16) bytes.
MEDIUMBLOB field is 16777216 (=2^24) bytes.
LARGEBLOB field is 4294967296 (=2^32) bytes
thus if you have large pictures, choose e.g.
MEDIUMBLOB instead of BLOB.
---
e.g.
creating a table to store pictures (in binary format) up to 16
megabytes:
---
--- cut here: begin --------------------------------------------------
CREATE TABLE `table1` (
`Photo` MEDIUMBLOB NOT NULL,
`PhotoFilename` VARCHAR(100) NOT NULL DEFAULT '',
);
--- cut here: end ----------------------------------------------------
---
e.g.
creating a table to store pictures (in binary format) up to 4
gigabytes:
---
--- cut here: begin --------------------------------------------------
CREATE TABLE `table1` (
`Photo` LARGEBLOB NOT NULL,
`PhotoFilename` VARCHAR(100) NOT NULL DEFAULT '',
);
--- cut here: end ----------------------------------------------------
---
---
Note:
Thus what happens when you insert a picture and filename in this
table (after you clicked on the 'browse' button),
is that such a data is inserted in this BLOB field.
--- cut here: begin --------------------------------------------------
INSERT INTO
`table1`
(
`Photo`,
`PhotoFilename`,
)
VALUES
(
0xff4...1234,
'mypicturefilename.jpg'
)
;
--- cut here: end ----------------------------------------------------
---
Here this value
0xff4...1234
is a binary representation of your picture.
---
---
Internet: see also:
---
Database: MySql: PHPRunner: Link: Can you give an overview of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/35950/fid/1805
----------------------------------------------------------------------