Jump to content

Get google spreadsheet doc data from URL present in the script


RoysonSilva

Recommended Posts

Hie,
 
I know there are many great logic idea mind out here.
I have a code for fetching CSV file data which uploads data and then fetch csv file and then fetch the content from the file and displays in the frontend.
Basically, the CSV file created is from the google doc spreadsheet.
Its a long process to first download the google spreadsheet in .csv extension and then to upload on my script and fetch the data.
But is there any better way to simply fetch data directly from google doc.
I tried but did not find a proper solution.
 

<?php
//if ($_FILES["https://docs.google.com/spreadsheets/d/1g-SMSAhkqot4BiQwDSw7pALnJAaEycg75eiBK6dz3Hc/edit#gid=0"]["error"] > 0)

if ($_FILES["file"]["error"] > 0)
{
   echo "Error: " . $_FILES["file"]["error"] . "<br>";

echo "No files...!!!!!";

echo "<script>alert('No files...!!!!!');window.location.href='upload_file.php';</script>";
}
else
{
   echo "Upload: " . $_FILES["file"]["name"] . "<br>";
   echo "Type: " . $_FILES["file"]["type"] . "<br>";
   echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>";
   //echo "Stored in: " . $_FILES["file"]["tmp_name"];
$a=$_FILES["file"]["tmp_name"];
$csv_file = $a; 

if (($getfile = fopen($csv_file, "r")) !== FALSE) {
        $data = fgetcsv($getfile, 1000, ",");
  while (($data = fgetcsv($getfile, 1000, ",")) !== FALSE) {
    //$num = count($data);
  //echo $num;
       //for ($c=0; $c < $num; $c++) {
           $result = $data;
       	$str = implode(",", $result);
       	$slice = explode(",", $str);
       
           $col1 = $slice[0];
           $col2 = $slice[1];
           $col3 = $slice[2];
}
}
}
?>

Could someone here please help me out.
Please let me know if any concerns.
 

 

 
 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.