• Hi guys, I need a little help here.

    I’m developing a webservice integrating Oracle Database to the WordPress Database, this code isn’t in the same wordpress server so I can’t use the wp_functions in general.

    My code is pure SQL/PHP and i’m inserting posts with pure SQL queries, these posts have images that I scan a folder and insert them in the database.

    I’m having trouble with the images metadata that I’ve insert previosly with pure SQL, in wordpress dashboard they apper with kind a noimage thumnail in Media section and I can’t regenerate the thumbnails.

    The query I’m executing to include the metadata is:
    "INSERT INTO wb_postmeta (post_id, meta_key, meta_value) VALUES ({$idPostImagens}, '_wp_attachment_metadata', 'a:5:{s:5:\"width\";i:{$imgWidth};s:6:\"height\";i:{$imgHeight};s:4:\"file\";s:24:\"produtos/{$SKU}/{$imgProduto}\";s:5:\"sizes\";a:20:{s:9:\"thumbnail\";a:4:{s:4:\"file\";s:17:\"{$filename}-150x150.{$fileExtension}\";s:5:\"width\";i:150;s:6:\"height\";i:150;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:6:\"medium\";a:4:{s:4:\"file\";s:13:\"{$filename}-300x169.{$fileExtension}\";s:5:\"width\";i:300;s:6:\"height\";i:169;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:12:\"medium_large\";a:4:{s:4:\"file\";s:13:\"{$filename}-768x432.{$fileExtension}\";s:5:\"width\";i:768;s:6:\"height\";i:432;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:14:\"post-thumbnail\";a:4:{s:4:\"file\";s:13:\"{$filename}-420x338.{$fileExtension}\";s:5:\"width\";i:420;s:6:\"height\";i:338;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:18:\"woostroid-thumb-xs\";a:4:{s:4:\"file\";s:11:\"{$filename}-81x65.{$fileExtension}\";s:5:\"width\";i:81;s:6:\"height\";i:65;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:17:\"woostroid-thumb-s\";a:4:{s:4:\"file\";s:13:\"{$filename}-150x150.{$fileExtension}\";s:5:\"width\";i:150;s:6:\"height\";i:150;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:22:\"woostroid-slider-thumb\";a:4:{s:4:\"file\";s:12:\"{$filename}-158x88.{$fileExtension}\";s:5:\"width\";i:158;s:6:\"height\";i:88;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:17:\"woostroid-thumb-m\";a:4:{s:4:\"file\";s:13:\"{$filename}-400x400.{$fileExtension}\";s:5:\"width\";i:400;s:6:\"height\";i:400;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:19:\"woostroid-thumb-m-2\";a:4:{s:4:\"file\";s:13:\"{$filename}-420x340.{$fileExtension}\";s:5:\"width\";i:420;s:6:\"height\";i:340;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:19:\"woostroid-thumb-m-3\";a:4:{s:4:\"file\";s:13:\"{$filename}-530x432.{$fileExtension}\";s:5:\"width\";i:530;s:6:\"height\";i:432;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:23:\"woostroid-thumb-masonry\";a:4:{s:4:\"file\";s:13:\"{$filename}-420x236.{$fileExtension}\";s:5:\"width\";i:420;s:6:\"height\";i:236;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:19:\"woostroid-thumb-l-2\";a:4:{s:4:\"file\";s:13:\"{$filename}-768x315.{$fileExtension}\";s:5:\"width\";i:768;s:6:\"height\";i:315;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:23:\"woostroid-author-avatar\";a:4:{s:4:\"file\";s:13:\"{$filename}-190x190.{$fileExtension}\";s:5:\"width\";i:190;s:6:\"height\";i:190;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:32:\"woostroid-woo-cart-product-thumb\";a:4:{s:4:\"file\";s:13:\"{$filename}-191x237.{$fileExtension}\";s:5:\"width\";i:191;s:6:\"height\";i:237;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:41:\"woostroid-thumb-products-smart-box-widget\";a:4:{s:4:\"file\";s:13:\"{$filename}-317x393.{$fileExtension}\";s:5:\"width\";i:317;s:6:\"height\";i:393;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:36:\"woostroid-thumb-listing-line-product\";a:4:{s:4:\"file\";s:13:\"{$filename}-672x432.{$fileExtension}\";s:5:\"width\";i:672;s:6:\"height\";i:432;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:32:\"woostroid-thumb-product-category\";a:4:{s:4:\"file\";s:13:\"{$filename}-436x432.{$fileExtension}\";s:5:\"width\";i:436;s:6:\"height\";i:432;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:21:\"woocommerce_thumbnail\";a:5:{s:4:\"file\";s:13:\"{$filename}-300x300.{$fileExtension}\";s:5:\"width\";i:300;s:6:\"height\";i:300;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";s:9:\"uncropped\";b:1;}s:18:\"woocommerce_single\";a:4:{s:4:\"file\";s:13:\"{$filename}-600x338.{$fileExtension}\";s:5:\"width\";i:600;s:6:\"height\";i:338;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:29:\"woocommerce_gallery_thumbnail\";a:4:{s:4:\"file\";s:13:\"{$filename}-317x393.{$fileExtension}\";s:5:\"width\";i:317;s:6:\"height\";i:393;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:12:\"shop_catalog\";a:4:{s:4:\"file\";s:13:\"{$filename}-300x300.{$fileExtension}\";s:5:\"width\";i:300;s:6:\"height\";i:300;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:11:\"shop_single\";a:4:{s:4:\"file\";s:13:\"{$filename}-600x338.{$fileExtension}\";s:5:\"width\";i:600;s:6:\"height\";i:338;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}s:14:\"shop_thumbnail\";a:4:{s:4:\"file\";s:13:\"{$filename}-317x393.{$fileExtension}\";s:5:\"width\";i:317;s:6:\"height\";i:393;s:9:\"mime-type\";s:10:\"{$imageMimeType}\";}}s:10:\"image_meta\";a:12:{s:8:\"aperture\";s:1:\"0\";s:6:\"credit\";s:0:\"\";s:6:\"camera\";s:0:\"\";s:7:\"caption\";s:0:\"\";s:17:\"created_timestamp\";s:1:\"0\";s:9:\"copyright\";s:0:\"\";s:12:\"focal_length\";s:1:\"0\";s:3:\"iso\";s:1:\"0\";s:13:\"shutter_speed\";s:1:\"0\";s:5:\"title\";s:0:\"\";s:11:\"orientation\";s:1:\"0\";s:8:\"keywords\";a:0:{}}}')"

    Someone can help me? I’m stuck.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    WP generates media list table thumbnails from the 150×150 “thumbnail” size image generated when an image file is uploaded. Be sure this image is available to the file system. Be sure $filename includes the image path relative to the /uploads/ folder. Depending on your media settings, $filename might have a value similar to 2019/02/foobar, or it might just be foobar.

    Additionally, the s17 or whatever prior to each string must have the correct character count for the subsequent string, so s:17:"{$filename}-150x150.{$fileExtension}"; is invalid unless you are sure that all adds up to a 17 char string.

    You also don’t need to escape double quotes within a single quote string. By doing so, the backslash becomes part of the data.

    It’s kind of a fool’s errand to attempt to manually create a serialized array. You really should create a properly structured PHP array, then pass it through serialize() and store the returned value in the DB. Then you don’t need to fuss with character counts and escaped quotes.

Viewing 1 replies (of 1 total)
  • The topic ‘Integrating WebService with WordPress’ is closed to new replies.