user1144031
user1144031

Reputation: 637

Uploading File from C Client to PHP Server

I got a C client which needs to upload a file to web server. I am opening the file and sending it using Windows libraries.

On the server side I would like to write a PHP script that save the file.

Question #1: Since this is not the usual HTML FORM POST to PHP - how do I transfer the filename along with it's data? Using POST '/upload.php?file=filename' and sending the data in the body is recommended? If i use this, i can grab the filename via $_GET and file content via $_POST.

Question #2: What happens if file spans more than 1 packet? I need to track the connection somehow on the PHP side to append the POST body to the file. Is there any clean way to do it?

Thank You!

Upvotes: 1

Views: 1092

Answers (1)

a sad dude
a sad dude

Reputation: 2825

You should try libcurl, it can do file upload too.

Alternatively, you can learn about multipart/form-data mime type and how it encodes files and metadata. In short, you split the request body in parts with a boundary, and add headers to each file.

Upvotes: 1

Related Questions