I am making my first android app..for that I need to store .doc file in mysql database and later open doc file in my android app..at present I have been able to upload .doc file in xampp but it gets stored in temp folder and gets deleted after the script is executed..anybody tell me how can i store .doc file in mysql using php
-
1Possible duplicate of [Uploading a word document, storing it on mysql and displaying it](https://stackoverflow.com/questions/28946900/uploading-a-word-document-storing-it-on-mysql-and-displaying-it) – Sean Dawson May 07 '18 at 05:43
-
1There are literally hundreds, if not thousands, of tutorials about uploading files with PHP. You shouldn't store the files in MySQL, you should store the path in MySQL and move the file to some folder in your app, unless you have some very specific reason for storing the actual file in the DB. – M. Eriksson May 07 '18 at 05:45
1 Answers
Just try this field type for file storing in Mysql DB.
field types: TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB
Example: CREATE TABLE uploads (id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, description CHAR(50), data LONGBLOB, filename CHAR(50), filesize CHAR(50), filetype CHAR(50) );
For more details pls follow this article : https://www.thoughtco.com/storing-data-and-files-in-mysql-2694013
Note: Storing a file in DB is bad practice.
Reason against storing files in the database: 1). The size of a binary file differs amongst databases. 2). Increases the size of the database. 3). It is more complicated to serve up the files to a website. In order to do it with binary columns, you have to write a handler to stream the file binary from the database. You can also do this even if you store file paths but you don't have to do this. Again, adding a handler is not impossible but adds complexity and is another point of failure. 4). You cannot take advantage of cloud storage.

- 86
- 3
-
thanks for your help..so where should I store .doc files..if its bad to store in database..my final aim is to retrieve .doc files that are stored on server on the click of button in my android app – Shanu May 07 '18 at 06:29
-
Upload your files to server rather than uploading into database. You can find so many scripts, for uploading files in php. After files gets uploaded just save the filename into database with path. You can try like this. – Bits Please May 07 '18 at 07:48
-
thanyou so much for your precious time..i successfully uploaded doc files on xampp.. – Shanu May 09 '18 at 10:11