Self-Hosting Your Download Files

FoxyCart supports downloadable items, but they only offer 100MB of download space for free and you have to store the files with them. If you have a lot of files you need to offer, you’d want a way to self-host your downloadables.There is a script at the FoxyCart wiki which helps you setup a self-hosted download, but it is a little involved and takes some integration to work directly with FoxyShop.

The guys at FoxyCart are planning to add native self-hosting in the future so I’ve been reluctant to build in any official support for self-hosting files as it is a little hacky. But if you need to build a site now, here’s a guide on how to do it. Note that setting this up requires a moderate level of PHP proficiency. If you aren’t comfortable working with PHP you may get a little disoriented.Before starting, there are a few things that you need to keep in mind. First, all files have to be stored in one directory and second, the product codes must be integers so for the FoxyShop integration you can’t use your own product code–it must be the post-id. Leave the product code field blank.

First, download the script from the FoxyCart wiki and unzip it on your computer. The readme.txt is very helpful and explains the script thoroughly. Open up the config.inc.php file and load in your API key and database connection information. If you don’t know it off the top of your head, you can get the information from your wp-config.php file. You’ll also need the path for your folder that contains all the downloadable files. If you don’t know your server’s path structure, you can get a pretty good idea of what it is from the top of the FoxyShop settings page. You’ll also want to customize the email wording a bit. If you use the HTML email, it doesn’t use the plain text version at all.

Next, you’ll need to install the two database tables that the script uses into your database. Upload your files to the server and go to the setup/install.php and run the installer.

The next step in the process is to connect your FoxyShop products to the script’s database. I’ve written some code which will help you do this. Download this code here and put it in your functions.php file. Use this code if you are using Amazon S3. Make sure that you update the path on line 11 and the if you have a custom table prefix for the script’s two tables, you’ll want to adjust that as well on line 37. After setting this up, products and their downloadable files will be in sync with the script at all times.

Finally, hook the generateLink.php file to your datafeed. You can do so either directly on the FoxyCart admin or if you need some of the FoxyShop datafeed features you can set it up as a third-party feed in the datafeed template file in your theme folder. Then do your tests! Your customers should be emailed their downloadable link after purchase.

I still think that this does not provide for the best user interaction because the customer can’t download the file immediately and is, instead, dependent on email for delivery of the files. Hopefully this will merely be a stopgap measure and we’ll have a better solution in place before too long.

2 Responses to Self-Hosting Your Download Files

Leave a Reply to David Cancel reply

Your email address will not be published. Required fields are marked *