4
누구나 curl을 사용하여 파일을 Google 문서에 게시하는 방법을 알고 있습니다. 는이 코드 쓰기 :Google 문서 도구 API 컬을 사용하여 파일 업로드
$header[] = "Authorization: GoogleLogin auth=seсretkey";
$header[] = "Content-Type: application/pdf";
$header[] = "Slug: testdoc";
$header[] = "Content-Length: ".$_FILES['file']['size']."";
$url = "http://docs.google.com/feeds/documents/private/full";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($_FILES['file']['tmp_name']));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
을 그리고 내가 텍스트 파일을 일반/텍스트 콘텐츠 형식을 사용하는 경우에만 잘 작동하지만 바이너리 모드에서 업로드 된 파일의 경우 내가 PDF로 예를 들어, 417 HTTP 오류 코드를 가지고 서류.
나는이
curl_setopt($ch, CURLOPT_POSTFIELDS, array("file"=>"@".$_FILES['file']['tmp_name']));
로 변경이 라인
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($_FILES['file']['tmp_name']));
을 시도했다하지만 난 다시 417 응답 오류 코드를 가지고있다. 만 일반에/텍스트 응답은 official source
POST /feeds/documents/private/full HTTP/1.1
Host: docs.google.com
Authorization: <your authorization header here>
Content-Length: 81047
Content-Type: application/vnd.ms-excel
Slug: Example Spreadsheet
... spreadsheet contents here ...
나는 이전에이 기사를 보았지만, 단지 varables를 게시하는 방법을 보여 주었지만 파일은 표시하지 않았다. ( – antyrat
Ahh shoot,이 링크를 시도해 보라. 그것은 CURL 맨 페이지의 일부이다 : (http : //www.cs.sunysb .edu/documentation/curl/index.html)는 "POST (HTTP)"헤더 아래에서 'cooltext.txt'파일 이동에 대해 논의합니다. – Shane