Convert uploaded document to binary/ascii and send as a api variable
I need to write a code which uploads doc file and send its content in binary or ASCII as a API variable .I can think of two approach (1)Upload the file and then read its content and send the data to api (2)Upload the file and then store its content and access the blob data and send to api.
I would like to ask which one is better. Right now i am using second option.
Now my problem is I am able to do upload part and storing to database part as a blob data , but when i access the blob data using mysql query and send result to API . The API says that its not in binary or ASCII . And when i echo the result of query it shows jibberish data so i assume that its not in binary or ascii . Please tell me how to pass this blob data to API as Binary/ASCII.
<?php
$filename = "resume3.doc";
$han开发者_Python百科dle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);
// URL of Form
$url = "http://rezscore.com/a/2901e8/grade";
//create the final string to be posted
$post_string = "resume=$contents";
//create cURL connection
$curl_connection = curl_init($url);
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
print $result;
//close the connection
curl_close($curl_connection);
?>
The file should be a resume and the api returns grade for the resume. http://rezscore.com/
Thanks
You could use direct way without MySQL. Just upload the file to some temporary directory and use http://php.net/fread to binary-safe read its content.
精彩评论