Picture on phpmyadmin - database

I would like to put photos in my phpmyadmin database but I can't find the solution that allows me to do so. I made an image array with a varchar but I can't find the path that allows to put an image. I thank you in advance for helping a young beginner ❤️

The best solution is to store the image as a file on disk and put the path to the file in the database (as a varchar or some other text type), then your application references the file instead of loading the BLOB data directly from the database. There are performance reasons that are well documented elsewhere that explain the intricate details better than I can, but basically the database slows and the amount of disk space it takes up expands as you store the images in the database.
If you decide to defy that advice and store the image directly in the database, you shouldn't be using phpMyAdmin as your main interface. Don't get me wrong, it's fully capable of uploading the image, but presumably you'll have some custom application interface that you should be using instead that also does application-level logic. But that's not what you asked, so to do this in phpMyAdmin, there should be a "Browse" button near the field on the phpMyAdmin Insert page. This requires your column be some appropriate sort of binary such as BLOB.

Related

How to store images in SQL Server

I do know that there is a answer here
But I want to know these:
I know how to save them programmatically, but I don't know what data type to save them? Could I still use image datatype when I have converted my images as image to 256KB? Or should I save them into filestream data type?
What kind of fragmentation is the document about? In my scenario, I have 2k+ employees and counting, so that means my application would get bigger over time, If I saved the images as image, and did not followed the rules as stated by the research paper, would my images lose their intact picture? (e.g a picture with blue background somehow changes its color maybe?)
Should I save it in the exact table of my employee details table? Or should I save it in a different table?
Sorry but I did not really understand the NTFS thing, is it the RAM of my computer? Or the RAM of my server? And I am using a file server as my database, should I still convert my images or should I go with using image data type without the conversion?
If you want to save files of any type in SQL Server then you should use the varbinary data type. You would use varbinary(max) unless you know that the files will be small. You can then convert your images to a Byte array and save that to the database.
You can enable the FILESTREAM option on your SQL Server instance these days and it will then store the data outside the main MDF file although that will be transparent to your code, so you keep using the same queries as you would otherwise.

Server backend: how to generate file paths for uploaded files?

I am trying to create a site where users can upload images, videos and other types of files.
I did some research and people seem to suggest that saving the files as BLOB in database is a Bad idea; instead, save the file paths in database.
My questions are, if I save the file paths in a database:
1. How do I generate the file names?
I thought about computing the MD5 value of the file name, but what if two files have the same name? Adding the username and time-stamp etc. to file name? Does it even make sense?
2. What is the best directory structure?
If a user uploads images at 12/17/2013, 12/18/2018, can I just put it in user_ABC/images/, then create time-stamped sub-directories 20131217, 20131218 etc. ? What is the best structure for all these stuff?
3. How do all these come together?
It seems like maintaining this system is such a pain, because the file system manipulation scripts are tightly coupled with the database operations(may also need the worry about database transactions? Say in one transaction I updated the database but failed to modify the file system so I need to roll back my database?).
And I think this system doesn't scale (what if my machine runs out of hard disk so I need to upload the files to a second machine? What if my contents are on a cluster?)
I think my real question is:
4. Is there any existing framework/design pattern/db that handles this problem?
What is the standard way of handling this kind of problems?
Thanks in advance for your answers.
I've actually asked this same question when I was designing a social website for food chefs. I decided to store the url of the image in a MySQL database along with recipe. If you plan on storing multiple images for one recipe, in my example, maybe having a comma separated value would work. When the recipe loaded on the page, I would fetch the image associated with that recipe onto the screen.
Since it was a hackathon and wasn't meant for production purposes, I didn't encode the file name into something unique. However, if I were developing for productional purposes, I would append the time-stamp to the media file name when storing it into the server and database/backend.
I believe what I've proposed is the best data structure of handling this scenario. Storing the image onto the server is not only faster, but it should also take less space. I have found that when converting a standard jpg file of reasonable resolution to base64 encoding, the encoded text file representation took 30% more space. There is also the time of encoding the file and decoding the file for storage and resolving when using some BLOB type of data format instead of straight up storing the file on the server.
Using some sort of backend server scripting like PHP, you'll be able to do some pretty neat stuff with the information you have available. Fetch the result from the database, and load it in from the page using HTML.
As far as I know, there isn't a standard way of fetching media from a database yet. Perhaps there will be one day.
There is not standard way to do that, it is different to the different application. The idea is you need generate a different Path+FileName for every upload, here is a way:
HashId = sha1(microsecond + random(1,1000000));
Path = /[user_id]/[HashId{0,2}]/[HashId{-2}];
FileName = HashId

Insert a image in imageview with url into sqlite DB without BLOB

I need to insert an image into a imageview with url into sqlite DB without using the BLOB, is possible??
Thanks in advance
Short answer: I am not aware of any way to save images in SQLite without using BLOBs, and BLOBs of images can be too large for the server to handle smoothly. But I won't claim to have thorough experience with SQLite, so there's a good chance I'm missing something.
Depending on what other resources are at your disposal, one solution would be to just store the url for the image in a TEXT type, but save the image in some other file system. Then when you want to display the image, query the database to get the address (plus whatever other relevant info), isolate it from the results, and query the file system for the image. Implementing this pattern will really depend on the environment your system will be working in; if it's an Android device, you can probably just refer to the filepath it started at, or save it to a dedicated folder; if it's a web interface, the images would most easily be saved as a sub-folder next to the web page(s) that use the images.

WinForms and Access Database Attachments

If I have a PDF file saved into an attachment field in an Access database, is there anyway I could get that attachment from the database and view it in the WinForm? Or the WinForm WebBrowser maybe?
Or am I just better off sticking to a field in the database that tells me the file path of said file so I can navigate my WebBrowser to that?
I've been working with Access since long before Access 2007 introduced the Attachments field type, so I have a history of shying away from imbedding images and documents in the database. (They tended to bloat the database quite significantly, and the OLE "wrappers" added to the files were a real nuisance when trying to extract the files via code.)
Access 2007+ makes this quite a bit simpler with the Attachments field because DAO has been updated to support .SaveToFile and .LoadFromFile on Attachments. Also, attachments are (apparently) compressed when saved to the database, which should help with the bloat problem.
So, I'd say that the choice is really up to you, because if you want to view (or preview, or open) the PDF attachment in your WinForm then you'll probably wind up using Microsoft.Office.Interop.Access.Dao to save the attachment as a temporary file anyway. Therefore, whatever mechanism you use to preview/view/open the attachment will be working on a file; it will either be
a temporary file extracted from the database, or
a persistent file in a filesystem that you reference from a pathname or URL in the database.
To read the file from the database you would need to read the bytes from the database and write them to a new pdf file, then point your viewer to that file. To view a pdf directly on the WinForm you would need a 3rd party control. If you have a plugin where you can view pdfs in your browser, the WinForm WebBrowser will work.
Storing just the path in the database leads to less hassle from a coding standpoint, because you are going to have to point your viewer to a file anyway. Also is theres an issue with the database, there is a higher chance all the attachments will be lost. On the flipside, if just the paths are stored you need to make sure those paths are always accessible.
I would recommend storing them outside of the database for the above reasons, especially if this is a larger database.

creating a video database

I am interested in creating a video databse. My goal is to have a folder where my videos will be kept and each time I copy/delete a video the website that presents them should be updated to. the problem is I have no idea how to approach it.
Should I..
Use Sql and store a reference to each video location?
Have a script that checks all the time if new changes happen in that folder?
A package like joomla?
I am using ubuntu btw. I already have a simple html5 page, and I am presenting the videos using html5 video.
It depends on the size and the performance you want.
1.Way : use php to scan the folder and generate links on the fly
2.way : Use a database to store the file names and retrieve the names from the database and generate urls
pros and cons.
simple to implement , no changes in upload or download script. no database required.
You need have a database , little coding required for upload and also while genrating a page
You should make a db (format does not matter) and storing in it only file names of videos: the videos would be stored on hard drive.
Any operation on the web site will pass first on db for insert/update/delete videos records and then (maybe in a transaction context) on the file system.
This would be the standard approach to your question.

Resources