Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8871009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:52:21+00:00 2026-06-14T17:52:21+00:00

I can create a file in Google Drive through a json into a Drive

  • 0

I can create a file in Google Drive through a json into a Drive folder:

$data = array(
    "title" => $_FILES['file']['name'],
    "parents" => array(array(
        "kind" => "drive#parentReference",
        "id" => $parent_id
    )),
    "mimeType" => "application/pdf"
);
$data = json_encode($data);

$url = "https://www.googleapis.com/drive/v2/files?oauth_token=".$accessToken;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

But I can’t find a way to add the PDF file on it, since no json attribute is specified on Google Drive Documentation.

Where would I have to add the file contents?
Is this possible?

Do I have to upload the file to upload/drive and then the metadata with the folder id? I don’t find the sense on that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:52:22+00:00Added an answer on June 14, 2026 at 5:52 pm

    You want to put the file in the body (i.e. in the CURLOPT_POSTFIELDS). You’ll want to specify Content-Type matching the file type and Content-Length as well.

    This is well documented.

    File metadata should be going to /drive/v2/files, not /upload/drive/v2/files.

    This way, you’d have to make two requests.

    If you want to do both a file and meta simultaneously, you can use the API and file insert:

    https://developers.google.com/drive/v2/reference/files/insert

    Note that there’s a PHP library to make this easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i create .KMZ (google earth file format) programmatically? .KMZ contains a .KML
Possible Duplicate: Can any one help me, to create .apk file for google android
How can I create a MSVC solution from a Google GYP File? There seems
How can I create an icalendar file with minimum data, I try to make
Can we create PDF file in android? I have Tried all Google Search. Also
I am trying to create a Google Drive app that can run in the
Under MacOSX, I can create a file under root (/) without having admin rights.
Hello all how can I create jar file of my project that is created
How can I create an empty file at the DOS/Windows command-line? I tried: copy
How can I create a .txt file using flex 3? And I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.