Skip to content

Multiple files upload support

In phpGrid, a column can support only a single file upload, per grid. 

To support more than one column to have upload capability, here's a workaround. Basically create a separate table that only used for storing image/file names with a reference key to the primary table. 

For example:

# (master)
|            Product           |
|__pk__|_color_|_size__|_price_|
| 100  | red   | large |   50  |
| 101  | blue  | small |   40  |
...

# (detail)
|          Product_Image       |
|_pk_|__image__|_fk_to_product_|
|  1 | img1.png|      100      |
|  2 | img2.png|      100      |
|  3 | img3.png|      100      |
|  4 | img1.png|      101      |
|  5 | img2.png|      101      |
...

Then you can use master detail table and enable file upload in detail table Product_Image. 

$dg = new C_DataGrid("SELECT * FROM product", "pk", "products");
$sdg = new C_DataGrid("SELECT * FROM product_image, "pk", "product_image");

$sdg -> set_col_fileupload("image");
$sdg -> enable_edit('FORM');

$dg -> display();

This approach enables product to have as many images as needed (1 to many) with file upload support for each different product.

Hope this helps!


Feedback and Knowledge Base