Skip to content
Advertisement

Request Entity Too Large PHP CURL

I have made a form to upload 2 images and send them to the SwiftDil API. I’m not sure where it all goes wrong, but at the end I get an error saying: 413 Request Entity Too Large.

First I save the file on my server in an directory. Then I use CURL and curl_file_create() to send the image from that directory to SwiftDil.

I can see that the images are stored in the directory. So I am not sure if the error comes from the server or from the curl function.

$fields = array(
    'front_side'        => curl_file_create('temp/' . $_FILES['front_side']['name']),
    'back_side'         => curl_file_create('temp/' . $_FILES['front_side']['name']),
    'type'              => $document_type,
    'document_number'   => $document_number,
    'issuing_country'   => $issuing_country
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url . "customers/" . $customer_id . '/documents');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Authorization: Bearer $newToken",
    "Cache-Control: no-cache"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

Files up to 500kb are sent well, but everything bigger returns the 413 error. I have no idea if it has something to do with the server where the script is running. ( I can only see that the files are actually uploaded to the server )

Advertisement

Answer

definitely a server problem. 413 means that whatever you’re trying to upload is too large. if you need to upload larger files, contact the api server admins about increasing the max upload size. (unless you are the server admin, in which case you should probably take your question to serverfault.com or superuser.com )

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement