A friend of mine told me that saving images in the database is not much of a good idea. Instead save it to the directory and then save it's name in the database and when I want to display the images in the browser I'm just going to use the name in the database to find the picture. Can anyone please guide me on how to do this starting from scratch?
Any help would be much appreciated.
By the way I am using php and MySQL.
Do two things:
accept more answers, here's how: https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work
read this tutorial: http://articles.sitepoint.com/article/php-gallery-system-minutes
What is it exactly that you don't know how to do? Your question seems to contain its own answer:
set up a directory for images, accessible to your web server
copy some image files in there
go to phpmyadmin and create a table with a filename field, for example of type varchar 100
store the image filenames in the table
write a php script that fetches image names and displays the HTML to load the images
Related
I am currently learning the CodeIgniter framework and would like some help with uploading/displaying images.
I am working with a customer table in which there is an 'avatar' field, which, as the name suggests, is a unique image which is reserved for and represents its respective customer.
I ask in this fashion because know that in C# and SQL Server, you can convert an image to "Binary" and save it in the DB; and likewise read the same "Binary" from the database, and convert it into an image.
I am wondering if the above, or something similar, is also possible in PHP...
After some research I see that most people are using the file location of the image, which I do not want to do. What's the point of type "BLOB" if I can simply save the location of the image instead?
If I am mistaken or misunderstanding any concepts please to clarify respectfully, that I may learn.
TLDR;
How do I go about saving/retrieving an image to and from the database without concerning myself with its file location? If this is impossible, then what's the point of "BLOB"?
I am working on WAMP and am using mysqld.
Sincere help is appreciated, thank you all in advance.
Blobs are ways of storing files and file systems in databases. Creating an image Blob will store the file in a container in your database. It is also a convenient way of packaging a number of files into a single database object. Blobs are not very widely used since it is generally simpler to access the file system containing the content directly.
Unsurprisingly most developers don't seem to enjoy the concept of 'filesystems inside of databases'.
I'm creating an interactive website where the user can upload a file.All I want to do is how can I let the other users see this file? For example if some datas are saved into database I can make this using SELECT and then print these data. But if I have a file how can I make this file to be seen only (not downloaded) from users?
So I just want to know what can I use to make this and don't want you to make this for me! So please if anyone has an ide please tell what should I learn to make this? Is it possible to save the file in a database in phpMyAdmin and to select then? If yes which is the type of the field I should use to save the file so varchar?
It depends on how you want the file to be saved. If it's a text file I would go with text. If it's an image or some other kind of media I would pick blob. You can take a look at What are the differences between the BLOB and TEXT datatypes in MySQL? for more information on MySQL data types.
Another approach would be to save the file somewhere outside the database (in a directory tree somewhere) and save a filepath to that location in a varchar column. Many DBMS do not support group by on blob or clob columns so that is something to consider if portability is an issue, and it adds a layer of separation between your data and file storage.
Does anyone know of a image tagging solution for websites that reads and writes the tag data to a database instead of a locally stored file? I've looked at http://jquery-notes.rydygel.de/index.php but the current version doesn't have database support. I just need a solution that can be used on all the mainstream browsers. The reason I don't want to read and write from a local file is because there might be a lot of images, and I don't want to store everything locally. Thanks!
You will be need to store the notes to a database table with following rows
ID
IMAGE_ID
LEFT
TOP
WIDTH
HEIGHT
DATE
NOTE
AUTHOR
LINK
And i believe the plugin has a php class for retrieving the notes. The file is notes.class.php
I know this should be really simple, but im having trouble getting this to work right, basically i want to have an image upload box that uploads an image and then puts the new url into a mysql database. Anyone have any advice on how to do this, as i may be having developer block but im over complicating it in my head :P Thanks
Uploading files using php.
Assuming some kind of LAMP server, the uploaded files will be placed in a temporary directory. You will have to move them from there to their final destination and I usually give the moved files a new file name to avoid any security problems. Of course the original file-name is available so you can keep it as well, either as a file-name or as an entry in a database.
What are you precisely having problems with?
I need a php code and sql code that will let someone upload an image to a database. The only thing I can find is very glictchy and not accepted by some browsers. Any ideas?
NEVER store images in the database. NEVER EVER EVER EVER. There are tons of other questions posted here about it that you may want to ready up on.
Always store directly on filesystem, and store the image URL of the file in the database.
If I understood correctly, you want to upload image files (or any files) via browser to the server and save them in the database. If that is the case, read this:
http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx
There are likely lots of available tutorials online to show you how to do this (you might take a look at this one: http://www.codewalkers.com/c/a/Database-Articles/Storing-Images-in-Database/).
I think that this is not the most efficient way to handle images, however. You might consider writing them to a folder and simply keep the name of the file and its location in the database. This stackoverflow question might help: How to store file name in database, with other info while uploading image to server using PHP?