Implementing file upload in PHP for HubSpot forms

I’m working on a project that uses HubSpot for marketing and email campaigns. So far, I’ve been able to handle forms, email templates, and workflows using the HubSpot PHP API. Now I need to add a file upload feature to my forms.

I tried adding a file upload button to my form, but when I check the submissions, there’s no info about the uploaded files. I’m not sure if I’m doing something wrong or if there’s a special way to handle file uploads with HubSpot.

Has anyone successfully implemented file uploads for HubSpot forms using PHP or JavaScript? I’d really appreciate some guidance on how to get this working. Maybe there’s a specific method or approach I should be using?

Here’s a basic example of what I’ve tried so far:

$form_data = array(
  'email' => '[email protected]',
  'name' => 'John Doe',
  'file' => '@/path/to/file.pdf'
);

$curl = curl_init('https://forms.hubspot.com/uploads/form/v2/{portal_id}/{form_id}');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $form_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);

Any tips or code snippets would be super helpful. Thanks!

hey Sky24, i’ve dealt with this before. hubspot doesn’t handle file uploads directly thru their forms API. wat u need to do is upload the file to ur own server first, then pass the file URL to hubspot. u can use something like this:

// upload file to ur server
$file_url = upload_to_server($_FILES['file']);

// send form data + file url to hubspot
$form_data = [
  'email' => '[email protected]',
  'file_url' => $file_url
];

hope this helps!