How to store 3000 image in mysql fast not one by one?

Recommended Answers

All 7 Replies

Create a single insert query. It may time-out though. Depends also on how you are accessing your images, and how you want to store them.

storing image in db is not recommended as you will be storing it in BLOB(Binary large object) datatype.So for storing it in Database it will be encoded in binary format and saved and will retrieving it will again decode.As you have so many files,it will be better you store it in some folder location and store the location with filename in Database.

i want to store image myself before i put my website online and then user make download from my site.If i store image filename for all image that is be long day..

no it is not required to be done can write a script to store,filename and your hardcoded location where all images will be and file type in db,copy all images to that location.
So table will be something like this.

FileIId INt not null auto_increment
FileName varchar(50) not null
FileType varchar(50) not null
FileLocation varchar(50) not null

your are stating the multiple file uploads right?

well there are some samples of multiple file uploads at one just like facebook. I don't know how to move this thread to Javascript section, but perhaps it will be the same and will pass down to PHP script for storing it to the database.

Things to consider.
Java script is the one who handles multiple file uploads at the browser view. for example, on the default script of html tag's input type file, it only handles one file at a time, to make it multiple selected, it needs Javascripting for that input type file tag by using either getElementByID or the name of the tag it self. make sure that the name attribute of the input type file has square brackets just like below:

<input type='file' name='myFiles[]' ID='myfiles'>
it will come in handy when your name attribute will be looking like a structure of an array at the html level. because this will help Java script to handle the files more quickier than easier.

Java script Level
create some sort of a function that you want in Java script level for enabling GUI upload window to handle more than one file at the UPLOAD files window. Do it on your own the way you want it. additionally, if you want some restrictions of which file type and how heavy the file should be at per element of the array. In this manner it will help PHP to make transactions more quickier and make the computation of PHP less time consuming.

PHP Level
Do not store the files in your database directly for much more easier to handle the database. use also $_FILES function in PHP to handle the name of the file, the capacity of the file and the file type of the file. Mostlikely, getting the file type and the file capacity is now available also on Java script. the only thing that you should store in the database is the result of $_FILES per element of an array not the file it self. If you store the files it self directly to the database, then your making your own a site that is not user friendly and it will be a pain in the ass, because it will be time consumable.

I have supported this multiple file upload in Java Query (jQuery) scripting. hoe it helps you alot. the serverside scripting would all be your logic now.

I prefer you to use HTML 5 version than Flash version for more stability.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.