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 922949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:06:53+00:00 2026-05-15T19:06:53+00:00

Working on a PHP script to essentially dump the results of a query into

  • 0

Working on a PHP script to essentially dump the results of a query into a .csv and then upload to a specific folder on our enterprise Google Docs.

The file is created and sent over to Docs just fine. However, it isn’t being placed in the proper directory.

This is the function I’m using where $file, $folder, and $newtoken are strings like 'dump.csv', '0B0rVKeOmIwGXMGU2MzYyN2EtZWV...', [auth token from Google].

function insert($file, $folder, $newtoken){
    $mime = "Media multipart posting\n--END_OF_PART\n";
    $mime .= "Content-Type: application/atom+xml\n\n";
    $xml="<?xml version='1.0' encoding='UTF-8'?>
    <entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:docs=\"http://schemas.google.com/docs/2007\">
        <category scheme=\"http://schemas.google.com/g/2005#kind\"
      term=\"http://schemas.google.com/docs/2007#document\"/>
        <title>example document</title>
        <docs:writersCanInvite value=\"true\" />
    </entry>
    ";
    $mime.=$xml."\n--END_OF_PART\n";

    $document = "Content-Type: text/plain\n\n";
    $handle = fopen($file, "r");
    $contents = fread($handle, filesize($filename));
    fclose($handle);
    $document.=$contents;
    $itemURL = "https://docs.google.com/feeds/default/private/full";
    $mime .= $document."\n--END_OF_PART--\n";

    $headers = array();
    $headers[] = "POST /feeds/default/private/full/folder%3A".$folder."/contents HTTP/1.1";
    $headers[] = "Host: docs.google.com";
    $headers[] = "GData-Version: 3.0";
    $headers[] = "Authorization: GoogleLogin auth=".$newtoken."";
    $headers[] = "Content-Length: ".strlen($mime);
    $headers[] = "Content-Type: multipart/related; boundary=END_OF_PART";
    $headers[] = "Slug: Test";

    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL,$itemURL);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl,CURLOPT_POSTFIELDS, $mime);
    $result = curl_exec($curl);
    curl_close($curl);

    echo 'Response: '.$result;
}

Maybe I have the folder ID wrong (just copied from URL while viewing in Google Docs)?
Bonus: Can I manipulate the content-type headers to get Google to convert the file to a spreadsheet?

  • 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-05-15T19:06:53+00:00Added an answer on May 15, 2026 at 7:06 pm

    You have

    $headers[] = "POST /feeds/default/private/full/folder%3A".$folder."/contents HTTP/1.1";
    

    and then:

    curl_setopt($curl,CURLOPT_URL,$itemURL);
    

    Make up your mind. I think the first one is wrong; you can’t change the URL via the CURLOPT_HTTPHEADER option. Set $itemURL to the full URL (including /feeds/default/private/full/folder%3A".$folder."/contents) and remove the first line.

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

Sidebar

Related Questions

I've got a working PHP script that gets Longitude and Latitude values and then
Can a PHP script (which can be working with a MySQL DB) send and/or
i have a problem, i'm working on a gallery php script and need help,
I'm working on a script in PHP that needs to get some info from
I'm working on a PHP application that links into the Protx VSP Direct payment
Okay so im working on this php image upload system but for some reason
If you are working in PHP (or I guess any programming language) and using
I'm used to working with PHP but lately I've been working with Java and
I am a web-developer working in PHP. I have some limited experience with using
I am working on a PHP application that intends to ease company workflow and

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.