gpt4 book ai didi

php - 将图像插入到 Prestashop 数据库

转载 作者:行者123 更新时间:2023-12-04 00:11:13 25 4
gpt4 key购买 nike

我正在制作一个简单的脚本,它将产品直接插入到 prestashop 数据库中,但我找不到如何将图像插入到数据库中。

到目前为止我的脚本是:

  mysqli_query($conn, 'INSERT INTO ps_product (id_supplier, id_manufacturer, id_category_default, id_shop_default, id_tax_rules_group, on_sale, online_only, quantity, minimal_quantity, price, wholesale_price, out_of_stock, active, redirect_type, available_for_order,  show_price, indexed, visibility, cache_default_attribute, date_add, date_upd, pack_stock_type,ean13,upc,unity,reference,supplier_reference,location) 
VALUES ("2", "2" , "5", "1", "1","1","1", "0", "1", "30", "30", "2", "1", "302","1","1","1","both","19",now(),now(),"3","0","0","","demo_1","","" )');


mysqli_query($conn, 'INSERT INTO ps_product_lang (id_product, id_lang, description, description_short, link_rewrite, name, available_now,meta_description,meta_keywords,meta_title,available_later)
VALUES (LAST_INSERT_ID(),"1","long des","test","insert title","title inserted","In stock","","","","")');


mysqli_query($conn, 'INSERT INTO ps_product_shop (id_product,id_shop,id_category_default,id_tax_rules_group,price,wholesale_price,unity,active,redirect_type,indexed,cache_default_attribute,date_add,date_upd )
VALUES (LAST_INSERT_ID(),"1","5","1","30","30","","1","301","1","1",now(),now())');

现在我必须在其中插入照片,以便我可以完成产品并发布它。

最佳答案

首先您需要在数据库中为您的图像创建一个新条目(表格图像)。如果您查看 Prestashop Image Class,它将图像存储在根据您的图像 ID 创建的目录下。您需要拆分图像 ID 的每个数字以获取路径。这是 Prestashop 图像类方法:

/**
* Returns the path to the folder containing the image in the new filesystem
*
* @param mixed $id_image
* @return string path to folder
*/
public static function getImgFolderStatic($id_image)
{
if (!is_numeric($id_image)) {
return false;
}
$folders = str_split((string)$id_image);
return implode('/', $folders).'/';
}

在 defines.inc.php 中,_PS_IMG_DIR_ 定义了您的图片文件夹(默认:/img/),_PS_PROD_IMG_DIR_ 定义了您的产品图片文件夹(默认值:p/)。默认情况下,产品图片的文件夹是 /img/p/

如果图像的 ID 为 927 且名称为“test.jpg”,它将存储在 /img/p/9/2/7/927.jpg

首先尝试对一些产品进行此操作,然后在 Prestashop BackOffice 中转到 Preferences > Images > regenerate thumbnails(在页面底部)。 Prestashop 应该为您生成每个产品的图像尺寸。

如果它不起作用或者您需要更多说明,请告诉我。

关于php - 将图像插入到 Prestashop 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34792567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com