PHP 8 image upload error running script

mreynolds
Excursionist
32 0 5

Hello PHP Expert,

 

We are trying to upgrade our PHP code that interfaces with Shopify from PHP version 7.3.11 to PHP version 8.2.8.  We have tested a number of interfaces to Shopify’s APIs via the new PHP version including fulfilling orders, creating products, updating products, and adding inventory.  However, when we try to add images via the /products/shopifyid/images.json API the images do not load.  The code works perfectly in 7.3.11 but not in 8.2.8.  We are posting to the API.  Adding inventory using the posting code and it works.  Adding the images is the only thing we found that doesn’t.

 

Here is PHP code and function we use to upload images. It is failing with PHP version 8.2.8

Errors are noted below.

 

function PostImages($ShopifyID,$ImageJSON)

{

              global $APIVersion; 

              return $this->sendAPIPost('https://cc0f71a6b1902f130kf14d4:132803ddca09ac394e81eak7a62@enescotest.myshopify.com/admin/api/'.$AP...);

}

 

private function sendAPIPost($url,$PostJSON)

{

 

              $ch = $this->curl;

              curl_setopt($ch, CURLOPT_URL, $url);

              curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

              curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

              curl_setopt($ch, CURLOPT_POST, 1);

 

              curl_setopt($ch, CURLOPT_POSTFIELDS, $PostJSON); 

              curl_setopt($ch, CURLOPT_HTTPHEADER, array('API-Key: '.$this->APIKey,'Content-Type: application/json'));

              $response = curl_exec($ch);

              $response = json_decode($response);

              return $response;

             

}

 

 

-------------------------------------Error message from PHP execution------------------------------------------------

Not loading images

 

Images Deleted for productID : 4024417

imageId:  34747590836411

imageSrc: https://cdn.shopify.com/s/files/1/2029/5281/files/4024417.jpg?v=1691692289

Image found : https://cdn.shopify.com/s/files/1/2029/5281/files/4024417.jpg?v=1691692289

imageId:  34747590967483

imageSrc: https://cdn.shopify.com/s/files/1/2029/5281/files/4024417_1.jpg?v=1691692291

Image found : https://cdn.shopify.com/s/files/1/2029/5281/files/4024417_1.jpg?v=1691692291

 

Images Created for productID : 4024417

ShopifyID : 9503986512    

{"image": {"src": "https:\/\/enesco.widen.net\/content\/jlims2hgeh\/jpeg\/4024417.jpeg?w=2000&h=2000&position=c&color=ffffffff&quality=80&u=upamz5"}}NULL

 

Warning: Attempt to read property "image" on null in C:\inetpub\wwwroot\Shopify\Onimd\UpdateProductImages.php on line 130

 

Warning: Attempt to read property "id" on null in C:\inetpub\wwwroot\Shopify\Onimd\UpdateProductImages.php on line 131

 

ShopifyID : 9503986512    

{"image": {"src": "https:\/\/enesco.widen.net\/content\/ocxy3dtgg0\/jpeg\/4024417_1.jpeg?w=2000&h=2000&position=c&color=ffffffff&quality=80&u=upamz5"}}NULL

 

Warning: Attempt to read property "image" on null in C:\inetpub\wwwroot\Shopify\Onimd\UpdateProductImages.php on line 130

 

Warning: Attempt to read property "id" on null in C:\inetpub\wwwroot\Shopify\Onimd\UpdateProductImages.php on line 131

 

Here is what we get using the prior PHP version of 7.3.11:

 

Here is a log from Current version.

 

Images Deleted for productID : 4059396

imageId:  29936672866388

imageSrc: https://cdn.shopify.com/s/files/1/0024/5799/3271/files/4059396SNOWP17.jpg?v=1688221660

Image found : https://cdn.shopify.com/s/files/1/0024/5799/3271/files/4059396SNOWP17.jpg?v=1688221660

 

Images Created for productID : 4059396

ShopifyID : 692922515511  

{"image": {"src": "https:\/\/enesco.widen.net\/content\/hqi0xqboq4\/jpeg\/4059396_0.jpeg?w=2000&h=2000&position=c&color=ffffffff&quality=80&u=upamz5"}}

 

Has anyone run into this issue when upgrading to the newest version of PHP?

 

Thanks, Margie

 

Replies 0 (0)