When I come to build a simple site using PHP and MySQL, what is the best method for storing paths of files and images?
C:/----
)http://----
)A Binary Large Object ( BLOB ) is a MySQL data type that can store binary data such as images, multimedia, and PDF files.
To use MySQL server on the command line, you must have the correct system path. This is usually done automatically.
MySQL stores each database (also called a schema) as a subdirectory of its data directory in the underlying filesystem. When you create a table, MySQL stores the table definition in a . frm file with the same name as the table. Thus, when you create a table named MyTable , MySQL stores the table definition in MyTable.
Always save file paths relative to your web sites directory. Consider your website's address is "foo.com" and you want to store images in "foo.com/images". It better to store images address without "http" and without "foo.com".
Therefore just save the filename and its subfolder if exists.
Neither, the best is to store just the filename and leave your application to determine where to locate this file. You can determine it accordingly to your database table. For example, let's say we have an user table which have an avatar field. You can store just the filename (foo.jpg), and then determine the path in your application (c:\xampp\htdocs\project1\img\users\foo.jpg). Or even better, you can leave this field and store nothing about the image, then you can check if an image exists with the id of the user, like 1.jpg, 2.jpg etc.
But, if you really want to store absolute paths, start storing from your project folder. For example, lets say you have c:\xampp\htdocs\my_project\module1
Then, start from /module1
If you need to store a external URL you can save the entire like http://www.foo.com/test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With