Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

Tutorial: Storing Images in MySQL with PHP
Started by
Guest_Jordan_*
, Mar 12 2008 04:40 PM
max_file_size mysql images php
47 replies to this topic
#37
Posted 24 August 2009 - 08:16 AM
I said I'd be back !! - lol
After a little head scratching, i realised blob is limited to 64k - So i changed to mediumblob (16Mb) and all is well.
Now the $64,000 question - Obviously, i don't want to be firing down lots of pics at this resolution (some of them are 1:1 scale engineering drawings, that may need to be printed). They are about 200k in size.
I see MySQL has a function to display thumb-nails - Am i better using this, or would it better to store a low-res version of the image in the database ?
I'm guessing saving the images at 92dpi for display purposes, and 'persueding' the code to switch over to the larger image when I select printer as the output would be logical. But before I commit to one way - can you suggest which path I should follow ?
Depending on the recommendation, it makes my next question of how to tell the display program which image to choose. My two CSS's may have to come to my help, here !!!
Once again, thanks for a well written and easy to follow tutorial - It didn't take very long to work out why the images weren't saving - and the ammendment was made easy owing to your clear commenting & use of variable names.
Regards,
Phill.
After a little head scratching, i realised blob is limited to 64k - So i changed to mediumblob (16Mb) and all is well.
Now the $64,000 question - Obviously, i don't want to be firing down lots of pics at this resolution (some of them are 1:1 scale engineering drawings, that may need to be printed). They are about 200k in size.
I see MySQL has a function to display thumb-nails - Am i better using this, or would it better to store a low-res version of the image in the database ?
I'm guessing saving the images at 92dpi for display purposes, and 'persueding' the code to switch over to the larger image when I select printer as the output would be logical. But before I commit to one way - can you suggest which path I should follow ?
Depending on the recommendation, it makes my next question of how to tell the display program which image to choose. My two CSS's may have to come to my help, here !!!
Once again, thanks for a well written and easy to follow tutorial - It didn't take very long to work out why the images weren't saving - and the ammendment was made easy owing to your clear commenting & use of variable names.
Regards,
Phill.
#38
Posted 27 August 2009 - 02:02 AM
Thanks Jordan, this helped me.
At last I will be able to +rep you


#39
Guest_Jordan_*
Posted 27 August 2009 - 06:57 AM
You are very welcome and thank you.
#40
Posted 12 October 2009 - 08:23 AM
Need some education. I looked around but didn't find an answer I understood or it doesn't matter anyway.
On this line:
<input name="image" accept="image/jpg" type="file">
My question is; what does accept="image/jpg" do for me? I can use this same code to upload jpg or pdf files. Should I worry about this to upload different file types?
Thanks,
Jon
On this line:
<input name="image" accept="image/jpg" type="file">
My question is; what does accept="image/jpg" do for me? I can use this same code to upload jpg or pdf files. Should I worry about this to upload different file types?
Thanks,
Jon
#41
Posted 12 October 2009 - 10:04 AM
Just saw this for the first time...
Great tutorial +rep
Great tutorial +rep

#42
Posted 13 October 2009 - 03:09 AM
Need some education. I looked around but didn't find an answer I understood or it doesn't matter anyway.
On this line:
<input name="image" accept="image/jpg" type="file">
My question is; what does accept="image/jpg" do for me? I can use this same code to upload jpg or pdf files. Should I worry about this to upload different file types?
Thanks,
Jon
I'm not too sure on the uploading of file types - but you do need to declare the mime type for them to display correctly.
Or, at least that's my understanding of the subject. If you declare a mime type of jpg and output a pdf file - it won't display correctly.
If anyone knows different, please correct me.
Phill.
#43
Posted 13 October 2009 - 11:27 AM
I do understand that you need the correct mime type to display the image.
My question is for uploading the image.
Jon
My question is for uploading the image.
Jon
#44
Posted 16 January 2010 - 08:35 AM
Cant wait in the nest tutorial i relly nid this tutorial for our proposal project in schools ^^
#45
Posted 09 June 2010 - 06:48 PM
This is my code
But in the database or the images/jpeg dot show image or anything in the database
<?php
require_once("startsession.php");
include_once("mysql.php");
$database = "binary";
?>
<form enctype="multipart/form-data" action="" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
<?php
// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Select your database
mysql_select_db ($database);
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO tbl_images ";
$query .= "(image) VALUES ('$data')";
$results = mysql_query($query, $link);
// Print results
print "Thank you, your file has been uploaded.";
}
else {
print "No image selected/uploaded";
}
// Close our MySQL Link
mysql_close($link);
?>
But in the database or the images/jpeg dot show image or anything in the database
#46
Posted 02 July 2010 - 01:24 AM
Hi!,
I am looking for the full script of image into database and show in php.After lot of searches I found your script which is working till ad.html and image into mysql.The real problem is like it is only showing show.php as Please select your image!.
I am not understanding where did the error occur.i even downloaded you script and tried the same thing is what it says.Please do help me its urgent for me for a portal I am doing where I need to upload images for each person registering and displaying their details.
Thanks and Regards,
Ram.
I am looking for the full script of image into database and show in php.After lot of searches I found your script which is working till ad.html and image into mysql.The real problem is like it is only showing show.php as Please select your image!.
I am not understanding where did the error occur.i even downloaded you script and tried the same thing is what it says.Please do help me its urgent for me for a portal I am doing where I need to upload images for each person registering and displaying their details.
Thanks and Regards,
Ram.
#47
Posted 14 July 2010 - 04:04 PM
This will be of great help to people. You have done a great job.
#48
Posted 04 January 2011 - 08:37 PM
The original poster is no longer with CodeCall. If you have any question regarding this posting, please start a new thread in the appropriate section of the forum (and reference this thread).
Thank you.
Thank you.
New around here? Click here to register and start participating in under a minute?
Or do a quick search and you may find the answer you're looking for.
Also tagged with one or more of these keywords: max_file_size, mysql, images, php
General Forums →
General Programming →
PHP code having some issueStarted by dennypaul, 09 Mar 2019 ![]() |
|
![]() |
||
Language Forums →
PHP →
Why mysqli_stmt_bind_result Fails ?Started by uniqueideaman, 25 Jul 2018 ![]() |
|
![]() |
||
General Forums →
Game Development →
Include a specific error, task, problem, or question in your titleStarted by Killuah, 04 Jul 2018 ![]() |
|
![]() |
||
General Forums →
The Lounge →
Projects and Site Reviews →
Wordpress ProblemStarted by mihosa, 06 Jun 2018 ![]() |
|
![]() |
||
Language Forums →
Databases →
Include a specific error, task, problem, or question in your titleStarted by Kriss, 27 Sep 2017 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download