Forums / Code Collaboration / Plugin download with curl

Plugin download with curl

Views: 161

Results 1 to 16 of 16
14 Sep 2026, 5:48 PM
#1
pilou2 avatar

pilou2

Zen Follower

Join Date:
Jun 2008
Location:
Japan
Posts:
413
Plugin Contributions:
6

Plugin download with curl

While testing on plugin manager, I was able to add a download function when new plugins version are available. It works fine as long as the zip file is on my server, it is downloaded and new version folder added to plugin folder. But when trying to download from Zencart server, curl returns the HTML code of a HTTP 404 error page...

The link I use for plugin files uses this format:

https://www.zen-cart.com/plugins/plugin-name-like-this/download

When using this link in my browser, the file download dialog box pops up and I can download the zip file. In a PHP script with curl, as sid above I got a 404 error (but no curl error).

I was wondering if some curl options are missing or if there is a protection on the sever to prevent scripts from downloading plugins?
The curl options I use are as folows:

        curl_setopt($ch, CURLOPT_TIMEOUT, 300);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Any info appreciated...

ZC v2.2.2 PHP 8.4+ MySQL 8.4+

15 Sep 2026, 10:09 AM
#2
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,305
Plugin Contributions:
39

Re: Plugin download with curl

Very likely something like CloudFlare is blocking this... BUT it is an amazing idea and should be pursued!

15 Sep 2026, 2:22 PM
#3
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,973
Plugin Contributions:
8

Re: Plugin download with curl

the following code block gave me 200 response code with no errors.

the $response seemed to have the download.

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://www.zen-cart.com/plugins/helcim-payments-by-mxworkscc-vb2402/download');
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 3);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 2);

    $response = curl_exec($ch);
    $error = curl_error($ch);
    $errno = curl_errno($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

best.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

15 Sep 2026, 5:16 PM
#4
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,862
Plugin Contributions:
18

Re: Plugin download with curl

The main trick is the addition of the --vb####

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

15 Sep 2026, 5:21 PM
#5
pilou2 avatar

pilou2

Zen Follower

Join Date:
Jun 2008
Location:
Japan
Posts:
413
Plugin Contributions:
6

Re: Plugin download with curl

I was trying to stream directly the download into a temporary zip file instead of saving it in a PHP variable and though it was the problem. But using your code did not change a think. It worked in command line but when integreted in ZC, same problem. The only difference was the URL hardcoded in one case and dynamicaly built in the other, the one that did not work.

The problem was in the building of this URL, older plugin use a format like this:

https://www.zen-cart.com/plugins/helcim-payments-by-mxworkscc-vb2402/download

Plugins submited with the new system are like this, without version number:

https://www.zen-cart.com/plugins/database-structure-compare-tool/download

I now use the link provided by the plugin server API to built the download link and it works fine. It is slow due to Plugin Manager doing multiple loadings but I can download a new plugin version in 2-3 cliclks and then upgrade it also in 2-3 clicks.

The code is available here for those who want to try:

https://github.com/piloujp/zencart/tree/Plugin_Update-Download_Available_Status_icons

Thanks for your help!

ZC v2.2.2 PHP 8.4+ MySQL 8.4+

15 Sep 2026, 5:25 PM
#6
pilou2 avatar

pilou2

Zen Follower

Join Date:
Jun 2008
Location:
Japan
Posts:
413
Plugin Contributions:
6

Re: Plugin download with curl

dbltoe:

The main trick is the addition of the --vb####

Yes right! I use the link provided by the server API like this (latestAvailable() method returns the content of the API response):

basename($this->latestAvailable()['link'])

I insert this in the url and everything is OK.

ZC v2.2.2 PHP 8.4+ MySQL 8.4+

15 Sep 2026, 7:18 PM
#7
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,807
Plugin Contributions:
22

Re: Plugin download with curl

pilou2:

I now use the link provided by the plugin server API to built the download link and it works fine.

Excuse me?! Plugin server API? There's an API???

About a year ago, I presented an idea for a Remote Plugin Installer which would allow you to browse available plugins from the admin and install them with a single click, but it was depending on an official API being available. Unfortunately, never heard back from Doc. Are you saying there IS an API endpoint for the plugins? Is there any documentation or info about it? I must've slept through that notice...

My site - Pro ZC Help
My portfolio | My plugins

15 Sep 2026, 7:47 PM
#8
pilou2 avatar

pilou2

Zen Follower

Join Date:
Jun 2008
Location:
Japan
Posts:
413
Plugin Contributions:
6

Re: Plugin download with curl

balihr:

pilou2:

I now use the link provided by the plugin server API to built the download link and it works fine.

Excuse me?! Plugin server API? There's an API???

About a year ago, I presented an idea for a Remote Plugin Installer which would allow you to browse available plugins from the admin and install them with a single click, but it was depending on an official API being available. Unfortunately, never heard back from Doc. Are you saying there IS an API endpoint for the plugins? Is there any documentation or info about it? I must've slept through that notice...

Well, I discovered this very recently, by looking into some plugin manager code...

If you send a plugin id to this URL:

https://ping.zen-cart.com/plugincheck/

With an array of plugin IDs using curl, you get a Json string with few information. For exemple for plugin 2445:

id: 2445

title: Admin Add Customer

latest_plugin_version: v1.2.2

latest_plugin_updated_date: 1789499130

latest_plugin_updated_date_formatted: 15 Sep 2026

filesize: 1210581

last_contributed_by: dbltoe

support_thread: /threads/207238

encapsulated: 1

zcversions: v2.0.0, v2.1.0, v2.2.0, v2.2.1, v2.2.2, v2.3.0, v3.0.0

zcversions_csv: v2.0.0, v2.1.0, v2.2.0, v2.2.1, v2.2.2, v2.3.0, v3.0.0

link: https://www.zen-cart.com/plugins/admin-add-customer-vb2445

ZC v2.2.2 PHP 8.4+ MySQL 8.4+

15 Sep 2026, 8:21 PM
#9
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,807
Plugin Contributions:
22

Re: Plugin download with curl

Ah, that's a bit different - I was hoping for something else. Here's a screenshot of the concept I mentioned - it requires an API that can provide info about available plugins and pull it from the repo into the website...

I was hoping there was something about THAT and I missed the memo. 😉

My site - Pro ZC Help
My portfolio | My plugins

18 Sep 2026, 3:46 PM
#10
pilou2 avatar

pilou2

Zen Follower

Join Date:
Jun 2008
Location:
Japan
Posts:
413
Plugin Contributions:
6

Re: Plugin download with curl

After solving the CURL problem, I did have a working Plugin Manager with download capabilities but it was really too slow. I changed my approach of the problem and I now have the same functionalities with a reasonable Plugin Manager page loading time, even with loads of plugins installed.

The server new plugins information are loaded one time in a class property and then accessed (many times) with a getter function during the building of the plugin listing.

If you want to test you can download the code from this branch: https://github.com/piloujp/zencart/tree/Plugin_download_Available-fast

There are still few problematic plugins, but it is due to their records in the library. Some use v155 for plugin version, others have v210 for ZC compatible version. These numbers without dot do not compare well with standard version numbers.

ZC v2.2.2 PHP 8.4+ MySQL 8.4+

18 Sep 2026, 5:35 PM
#11
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,927
Plugin Contributions:
3

Re: Plugin download with curl

Just a quick note here.

The new website does in fact have an API for plugins.

I haven't advertised this yet as it is still in an alpha phase.

You can see some output for one endpoint
https://www.zen-cart.com/api/v1/plugin-types

I do have other endpoints for plugins/plugin releases but not going to release that info till I have some better security

18 Sep 2026, 6:43 PM
#12
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,807
Plugin Contributions:
22

Re: Plugin download with curl

Oooooh, this is some good news! I'm assuming a Remote Installer WILL eventually be possible using that API? If so, have you taken into consideration screenshots from the plugin itself being displayed to represent the plugin, or will it be limited to a plain list?

My site - Pro ZC Help
My portfolio | My plugins

18 Sep 2026, 6:46 PM
#13
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,927
Plugin Contributions:
3

Re: Plugin download with curl

Yes, Auto install is the goal and I do have working code to do this

I haven't factored in screenshots but will think about it

18 Sep 2026, 6:51 PM
#14
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,807
Plugin Contributions:
22

Re: Plugin download with curl

Yeeeehaw!!! Can't wait to see it! Thanks for all the effort you're putting into this! Who knew Geordies were actually likeable... 😛

My site - Pro ZC Help
My portfolio | My plugins

18 Sep 2026, 6:53 PM
#15
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,927
Plugin Contributions:
3

Re: Plugin download with curl

FFS Geordies are the most likeable people
Unless you are a Mackem 🙂

18 Sep 2026, 7:00 PM
#16
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,807
Plugin Contributions:
22

Re: Plugin download with curl

Yeah, well, compared to Mackems, ya aaight, but it's not like you've raised the bar very high... 😉

Jokes aside, mate - thanks for the efforts in reviving Zen Cart! Cheers!

My site - Pro ZC Help
My portfolio | My plugins