PHP and database

Asked

Viewed 88 times

0

Great, I’m working on a website and I need to store a file inserted/uploaded by the user in a database. What type of data should I assign to the field?

  • Take a look at this link -> http://blog.fabianobento.com.br/2009/09/armazenar-arquivos-em-modo-binario-mysql-usando-php/

  • Uses BLOB or VARCHAR, depends on file size.

  • I tried to use MEDIUMBLOB but does not recognize the type of data

  • Use VARCHAR and set a good size for it, DB will store a reference to your file and not the file itself.

  • what do you mean by the phrase "I tried to use MEDIUMBLOB but does not recognize the type of data" ?

3 answers

1

Use VARCHAR by placing the physical path on the server. Do an analysis of the entire application to see if it is not necessary to have a table only for files, so you could put more information about the files in this table.

Like:

  • physical path on server
  • file url
  • file size

Among other various information that could come from the archive.

0

Use a VARCHAR and store only the physical file path on your server

0

If the file link is complete with http://... use VARCHAR sized 250 (maximum supported in a VARCHAR field). If you see that the field is too long and exceeds 250 characters, use TEXT that supports many characters.

  • The VARCHAR type is 0~255 for versions up to 5.0.3. Above this version is 0~65535. The CHAR type is more appropriate.. https://dev.mysql.com/doc/refman/5.0/en/char.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.