These instructions assume that you will use two web forms and a thank you page. The first web form is a normal Infusionsoft web form that collects all information except the files to be uploaded.
The thank you page of the first Infusionsoft web form is set to the second, non-Infusionsoft web form that will upload the files. When setting up the thank-you page, you must be sure to check the box that says “Send contact information to the thank you page.”
NOTE: In the image above, the path to the File Submit form is set to path on our server. You will need to change to the path for your second form.
The File Submit Form below is just a skeleton form with no styling. You will want to spruce this up and make it match your branding with a little CSS.
Here is the code for the File Submit web form, cb_upload_files_form.php. (We recommend you download the files, FTP to your server and then edit to make any necessary changes. Sometimes the copy and paste process changes characters that can break the code.)
<!doctype html> <?php // Assign REQUEST variables using ternary operators and IF statement if ($_GET['Id']) { $contactId = $_GET['Id']; } else { $contactId = ($_GET['contactId']) ? $_GET['contactId'] : ''; } ?> <html> <head> <title>FileBox Upload</title> </head> <body> <div id="TAG-filebox-form"> <form action="cb_upload_files.php" method="POST" enctype="multipart/form-data"> <input type="hidden" name="contactId" value="<?php echo $contactId ?>" /> <div style="overflow: auto; min-width: 300px;"> <div style="float: left; margin-top: 3px; margin-right: 10px;"> Select your files: </div> <div style="float: left;"> <input type="file" name="files[]" multiple /> </div> </div> <div style="margin-top: 10px;"> <button type="submit">Upload</button> </div> </form> </div> </body> </html>
Lines 6 – 10, of the File Submit Form, pull the Contact ID being passed by the first form and use it to pre-populate a hidden Contact ID Field. That will make sure the files are uploaded to the Filebox of the contact you you just added or updated.
The POST Submit action on Line 21 is the path to the script that encodes and uploads the files and then redirects the user to a thank you page. You should not need to change that path unless cb_upload_files.php is in a different directory than the File Submit Form.
<form action="cb_upload_files.php" method="POST" enctype="multipart/form-data">
Line 22 contains a hidden Contact ID field that is being populated with the Contact ID that was passed, from the first form, by the code:
<input type="hidden" name="contactId" value="<?php echo $contactId ?>" />
Note: this code is for an html form in a PHP file. If you put this form on a WordPress page, you will have to use a different means to populate the hidden field. One way would be the URL Params plug-in by Jeremy Shapiro. Another would be jquery or javascript.
Line 28 is the multi-file picker. You should not need to change this line.
On Submit, this form will submit to the File Upload script, cb_upload_files.php, which will upload the files to the contact’s filebox, in Infusionsoft, and then redirect to a thank you page.
Again, we recommend you download the files from Github, FTP to your server and edit accordingly. Cut and paste can make some files go wonky.
<?php $currentDate = date_format(date_create(), 'Ymd H:i:s'); if(count($_FILES['files']['name'])) { // Connect to Infusionsoft require_once __DIR__ . '../../lib/Infusionsoft/isdk.php'; $app = new iSDK; $contactId = $_POST['contactId']; // If connected if ($app->cfgCon("yourConnectionName")) { // Set $fileUploadSuccess to true $fileUploadSuccess = 1; // Loop through each file to be uploaded foreach ($_FILES['files']['tmp_name'] as $index => $name) { $userFileName = $_FILES['files']['name'][$index]; $userTmpFile = $_FILES['files']['tmp_name'][$index]; #open the file $fileOpen = fopen($userTmpFile, 'r'); #read the data and save it to a variable $data = fread($fileOpen, filesize($userTmpFile)); #close the file fclose($fileOpen); #encode the data from the file in base 64 #infusionsoft needs the data to be in this format to store it properly $dataEncoded = base64_encode($data); #upload file into app $uploadFile = $app->uploadFile($userFileName, $dataEncoded, $contactId); // write result to log file for troubleshooting $file=fopen("file_error_log.txt","a+"); fwrite($file, "n $currentDate n"); if ($uploadFile) { fwrite($file, "Uploaded $userFileName for ContactId $contactId Upload Id is $uploadFile n"); } else { fwrite($file, "Unable to upload $userFileName for ContactId $contactId Upload Id is $uploadFile n"); // change $fileUploadSuccess to false $fileUploadSuccess = 0; } $file=fclose($file); } // redirect to thank you page if ($fileUploadSuccess == 1) { header("location: http://theapiguys.com/thank-you/"); } else { echo "There was a problem with file upload. Please inform site administrator."; } } else { echo "Not Connected..."; } } else { echo "There are no files to be uploaded!";}
There are three things you will need to change in this script to make it work. First, on Line 9, you will need to change the path to the proper path on for the iSDK on your server.
require_once __DIR__ . '../../lib/Infusionsoft/isdk.php';
NOTE: This assumes you have already set up the iSDK on your server. If not, you will need to do that first. You can get instructions in our Missing Guide to Setting Up The Infusionsoft API.
Next, on Line 15, you will need to change the connection name to the one in your conn.cfg.php file.
if ($app->cfgCon("yourConnectionName")) {
And finally, on Line 60, you will need to change the URL to the URL of the your thank you page. This is where the user ends up when the process has completed successfully.
header("location: http://theapiguys.com/thank-you/");{
Remember, if you decide this is just not the best use of your time, we can set the Files To Filebox project up for you, with our Dunne, Foryoo & Phast implementation service. Just click over to the order form, tell us how you want it set up and we will get on it right away.
Also, if you have any questions about the project, you can post them in the comments below, which would be great, because it shows Google this page is happening … or go to our new API Guys Facebook Page. Either way, we promise we will answer.