0

I use code for send zip file and this work good:

$file = ''.$_SERVER['DOCUMENT_ROOT'].'/projects/file.zip'; $data = array( "file" => new CURLFile($file), "data" => '{"title":"Test"}' ); $handle = curl_init(); curl_setopt($handle, CURLOPT_URL, 'https://example.com'); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($handle, CURLOPT_HTTPHEADER, array( 'Content-type: multipart/form-data;', )); curl_setopt($handle, CURLOPT_POSTFIELDS, $data); $final = curl_exec($handle); $response = json_decode($final, true); curl_close ($handle); 

But when I send a file with the .keystore extension, nothing works. I do not receive errors on the server.

How do I properly send such a file?

2
  • 1
    The filename (including extension) or even content of a file shouldn't make any difference to how you send it; all CURLFile is doing is reading the contents of the file and transmitting it in a suitable encoding. Commented Jan 4, 2019 at 12:17
  • You're right. I spent a lot of time. The error was in the file path.) Commented Jan 4, 2019 at 12:22

1 Answer 1

2

you can try this

$file = ''.$_SERVER['DOCUMENT_ROOT'].'/projects/file.zip'; $mime = mime_content_type($file); $info = pathinfo($file); $name = $info['basename']; $output = new CURLFile($file, $mime, $name); $data = array( "file" => $output, "data" => '{"title":"Test"}' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://example.com'); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $result = curl_exec($ch); if (curl_errno($ch)) { $result = curl_error($ch); } curl_close ($ch); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.