Reputation: 399
I got the docs from the third party that is sending me a file over http protocol and I need to write a script that will successfully receive the sent file. Content-type is set as application/gzip
so I can't pick up the file uploaded using a $_FILES
variable as it would be easy with multipart/form-data
.
This link gave me a hint: http://php.net/manual/en/features.file-upload.post-method.php
Note: Be sure your file upload form has attribute enctype="multipart/form-data" otherwise the file upload will not work.
I tried to reproduce their "client" side to test my server using the example in the following url http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/
And to ensure crosdomain posting is available, I used a function posted and explained by @slashingweapon CORS with php headers
There must be a way to do it - Halp!
Upvotes: 2
Views: 111
Reputation: 399
Thanks to @fusion3k who pointed me to the right direction.
$rawData = file_get_contents("php://input")
gave the the RAW data from which I had to parse the file from. It was painful to extract it because it was a binary file. I used
$rawData = explode("\n", $rawData)
$valuableData
$convertedLine = unpack("H*", $valuableData[count($valuableData)-1])
$convertedLine[1] = substr($convertedLine[1], 0, -2)
( have no idea why is `unpack returning an array)$valuableData[count($valuableData)-1] = pack("H*", $convertedLine[1])
implode("\n", $valuableData)
and write that to a file Upvotes: 0
Reputation: 2553
Hi what I understand is you just need to download the file that has been uploaded to a server, try getting the file in binary mode using the below code:
ftp_fget($conn_id, $file, FTP_BINARY, 0);
Ref: http://php.net/manual/en/function.ftp-get.php
The connection details must be shared with you by the 3rd party who is sharing the file.
Upvotes: 0