Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

- - - - -

Tutorial: Storing Images in MySQL with PHP

max_file_size mysql images php

  • This topic is locked This topic is locked
47 replies to this topic

#37 phillw

phillw

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 72 posts

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.
  • 0

#38 Vswe

Vswe

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1989 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript

Posted 27 August 2009 - 02:02 AM

Thanks Jordan, this helped me. :) At last I will be able to +rep you :P
  • 0

#39 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 27 August 2009 - 06:57 AM

You are very welcome and thank you.
  • 0

#40 ezcat

ezcat

    CC Regular

  • Member
  • PipPipPip
  • 39 posts

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
  • 0

#41 debtboy

debtboy

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 499 posts

Posted 12 October 2009 - 10:04 AM

Just saw this for the first time...
Great tutorial +rep :thumbup:
  • 0

#42 phillw

phillw

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 72 posts

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.
  • 0

#43 ezcat

ezcat

    CC Regular

  • Member
  • PipPipPip
  • 39 posts

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
  • 0

#44 scumbogs

scumbogs

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 16 January 2010 - 08:35 AM

Cant wait in the nest tutorial i relly nid this tutorial for our proposal project in schools ^^
  • 0

#45 frozie

frozie

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 09 June 2010 - 06:48 PM

This is my code
<?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
  • 0

#46 raman_di

raman_di

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

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.
  • 0

#47 bobmacans

bobmacans

    CC Lurker

  • Just Joined
  • Pip
  • 7 posts

Posted 14 July 2010 - 04:04 PM

This will be of great help to people. You have done a great job.
  • 0

#48 Roger

Roger

    Skadoosh!

  • Administrator
  • 1222 posts
  • Programming Language:C, PHP
  • Learning:Others

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.
  • 0

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