There are two ways to store images:
- As files on a server and the path to the file is stored in the database
- Whole image is stored in the database
In most projects images are stored on the server and only paths are stored in the database. This is an old discussion you can read about here: Storing Images in DB - Yea or Nay?
If you have a .csv with the whole images stored in a text column (this is pretty unlikely) you may set up a TEXT
or a BLOB
column in your database.
The recommended way is to store images as files on the server. Therefore what you need in your project is a .csv column containing one or more image names or image paths.
In this case you have to seperate the process of importing data and importing files somehow.
However you can all do it within one import action for the user this is one example:
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="mycsv" />
<input type="file" name="images[]" multiple="multiple" />
</form>
You also could upload your files via ftp or use a file upload library this entirely depdends on the use case and on how big amounts of data you have to handle.
If you have a large amount of data (e.g. more than 100 products per .csv file) the process I recommend is like this:
Import your .csv into the database including image names or paths (within your upload script you can alter or extend the image path)
Copy your images to the server (e.g. via FTP) or via a seperate upload script - just make sure the image names / paths are matching