I have created a form in Wordpress using gravity forms, which includes a file upload field. On completion of the form I am using a webhook, setup within Gravity forms elite plugin, to pass the form fields into a PHP script which then uploads the data into an external system via API.
The issue is that when I complete the form without a file uploaded it works great, all of the fields are passed into PHP variables and script runs. However when the form does include a file upload field the script fails with no output to the error log.
I have re-created the problem with a much more simple form and script to confirm that this is the issue, my test form contains two fields a field upload and single line text field. My simple test script looks like this:
<?php
$output = var_export($_POST, true);
error_log($output);
?>
When the form is submitted with no file attached the log file shows the following variables outputted:
[01-Feb-2018 21:44:36 Europe/London] array (
'id' => '1166',
'form_id' => '17',
'date_created' => '2018-02-01 21:44:34',
'is_starred' => '0',
'is_read' => '0',
'ip' => '82.**.**.246',
'source_url' => 'http://****.******.co.uk/?gf_page=preview&id=17',
'currency' => 'USD',
'created_by' => '1',
'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
'status' => 'active',
1 => 'Test No Photo',
2 => '',
)
Note: The source url and IP have been masked the actual log contains the correct IP and URL.
However, as soon as I include a file upload in the form and then send this to the script nothing is outputted to the log at all and the script does not appear to run.
It's worth noting that the request does work with Requestbin. Here is the output from there including data which comes from the upload field:
is_starred: 0
id: 1163
1: Test with Photo
user_agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
created_by: 1
source_url: http://***.****.co.uk/?gf_page=preview&id=17
ip: 82.**.***.246
form_id: 17
status: active
currency: USD
2: http://****.***.co.uk/wp-content/uploads/gravity_forms/17-b570285e8ba734ff4ab3956428bd8eb9/2018/02/Child26.jpg
is_read: 0
date_created: 2018-02-01 20:48:20
The raw body is:
id=1163&form_id=17&date_created=2018-02-01+20%3A48%3A20&is_starred=0&is_read=0&ip=82.**.***.246&source_url=http%3A%2F%2F***.***.co.uk%2F%3Fgf_page%3Dpreview%26id%3D17¤cy=USD&created_by=1&user_agent=Mozilla%2F5.0+%28Windows+NT+10.0%3B+Win64%3B+x64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F63.0.3239.132+Safari%2F537.36&status=active&1=Test+with+Photo&2=http%3A%2F%2Fwww.********.co.uk%2Fwp-content%2Fuploads%2Fgravity_forms%2F17-b570285e8ba734ff4ab3956428bd8eb9%2F2018%2F02%2FChild26.jpg
Again I have removed the actual domain name but the rest of the request is as shown in Request Bin.
So can anyone please help me work out why the file upload value in the post data above would cause PHP to grind to a complete stop without an error message? Is there anything I can do to access this variable from the array in PHP in the same way Request Bin does?
Do I have to somehow decode the value before I can use it in a script/output it to the log? As a side note in my actual script I don't dump all the variables to a log this is just to show it in it's most simple example, in my main script they are selected one by one and assigned to variables using var = $_POST["1"] etc.
Edit:
I have enabled the logging option in Gravity Forms, it confirms the POST data content sent is:
[body] => Array
(
[id] => 1167
[form_id] => 17
[date_created] => 2018-02-01 22:31:42
[is_starred] => 0
[is_read] => 0
[ip] => 82.**.***.246
[source_url] => http://***.***.co.uk/?gf_page=preview&id=17
[post_id] =>
[currency] => USD
[payment_status] =>
[payment_date] =>
[transaction_id] =>
[payment_amount] =>
[payment_method] =>
[is_fulfilled] =>
[created_by] => 1
[transaction_type] =>
[user_agent] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
[status] => active
[1] => Test No Photo
[2] => http://***.***.co.uk/wp-content/uploads/gravity_forms/17-b570285e8ba734ff4ab3956428bd8eb9/2018/02/miniserver-image.jpg
)
Is there anything about variable 2 which would cause my PHP script to crash when it dumps the POST data to a log file? (I've removed the domain and IP in the code above.)
Thanks
WP_DEBUG = true
? Is the max post data for your server high enough to accommodate the file you're uploading? Is Gravity forms uploading the file as a multi-part request thus in the$_FILES
array, or is it encoding the file before uploading, and passing it in the$_POST
array? – fubar