Thursday 20 August 2015

Fetch Array Data from Server,JSON or Mysql Database, Insert it into EXCEL/CSV File and mail it.

Hi Guys,
here we have a complete solution of how to fetch data from server in the JSON format, php array format or java script array format and insert data into excel file or CSV file, and mail it through by PHP MAIL Function.

<?PHP

  $data = array(
    array("firstname" => "Mary", "lastname" => "Johnson", "age" => 25),
    array("firstname" => "Amanda", "lastname" => "Miller", "age" => 18),
    array("firstname" => "James", "lastname" => "Brown", "age" => 31),
    array("firstname" => "Patricia", "lastname" => "Williams", "age" => 7),
    array("firstname" => "Michael", "lastname" => "Davis", "age" => 43),
    array("firstname" => "Sarah", "lastname" => "Miller", "age" => 24),
    array("firstname" => "Patrick", "lastname" => "Miller", "age" => 27)
  );     // these are the manual data in the php array format.
  //echo $dataReceived = json_decode($_REQUEST['data'], TRUE);  //recieve data from json file

  function cleanData(&$str)
  {
    $str = preg_replace("/\t/", "\\t", $str);
    $str = preg_replace("/\r?\n/", "\\n", $str);
    if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
  }

  // file name for download
  $dir = "./excel/";
  $filename = "$dir"."website_data_" . date('Ymd') . ".xls";
  $fd = fopen ($filename, "w");
 
 
 // header("Content-Disposition: attachment; filename=\"$filename\"");
 // header("Content-Type: application/vnd.ms-excel");  //if we want to download file

// if we use json format then change foreach($data as $row)  to foreach($dataReceived as $row)
  $flag = false;
  foreach($data as $row) {
    if(!$flag) {
      // display field/column names as first row
      $filehead = implode("\t", array_keys($row)) . "\n";
 fputs($fd, $filehead);
      $flag = true;
    }
    array_walk($row, 'cleanData');
    $filecontent = implode("\t", array_values($row)) . "\n";
 fputs($fd, $filecontent);

  }
 
    $from_name = "From Name";
$from_mail = "vinod161191@gmail.com";
       $to = "vinod161191@gmail.com";
       $subject = "data in excel format";
     //  $message = $_POST['user_message'];

       //things u need
       $file = $filename;
       $content = chunk_split(base64_encode(file_get_contents($file)));
       $uid = md5(uniqid(time()));  //unique identifier

       //standard mail headers
$header = "From: ".$from_name." <".$from_mail.">\n";
   // $header .= "Reply-To: ".$replyto."\n";
    $header .= "MIME-Version: 1.0\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\n\n";
    $emessage= "--".$uid."\n";
    $emessage.= "Content-type:text/plain; charset=iso-8859-1\n";
    $emessage.= "Content-Transfer-Encoding: 7bit\n\n";
    $emessage .= $message."\n\n";
    $emessage.= "--".$uid."\n";
    $emessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\n"; // use different content types here
    $emessage .= "Content-Transfer-Encoding: base64\n";
    $emessage .= "Content-Disposition: attachment; filename=\"".$filename."\"\n\n";
    $emessage .= $content."\n\n";
    $emessage .= "--".$uid."--";
   


       //sending the mail - message is not here, but in the header in a multi part

       if(mail($to,$subject,$emessage,$header)) {
       echo "success";
       }else {
           echo "fail";
       }



  exit;
?>

Wednesday 11 March 2015

Zindagi Jeena sikha deti hai

Zindagi Jeena sikha deti hai!
Gum me peena sikha deti h!!
Bigde Halaat me v uthna seekho dosto,
Ye Halaat hi hme chalna sikha deti h.



Vinod Pal :::https://www.facebook.com/vinodpal161191 ::::
Vinod Pal ::: https://plus.google.com/+VinodPal16/:::::::::::
Vinod Pal :::https://twitter.com/vinodpal161191 :::::
Vinod Pal ::::https://www.linkedin.com/in/vinodpal161191 :::
Vinod Pal ::http://vinodpal161191.blogspot.in/ :::
Vinod Pal :::: https://www.youtube.com/c/VinodPal16::::::

 Vinod Pal


Monday 9 March 2015

Something confused about my decision

sometimes i feel that I am always right but sometimes i did't decide that what is wrong and what is right. when i decide to do a big project, many types of problem happens. I think i am always trying to do beyond to my capability. so i am always be fail. 
i think everything is happens according to the right time.


Vinod Pal :::https://www.facebook.com/vinodpal161191 ::::
Vinod Pal ::: https://plus.google.com/+VinodPal16/:::::::::::
Vinod Pal :::https://twitter.com/vinodpal161191 :::::
Vinod Pal ::::https://www.linkedin.com/in/vinodpal161191 :::
Vinod Pal ::http://vinodpal161191.blogspot.in/ :::
Vinod Pal :::: https://www.youtube.com/c/VinodPal16::::::  


 Vinod Pal

Saturday 7 March 2015

Feeling Enjoy in my Previous Company

I feel so relax and lot of fun with my friend Deepak Kumar in Saturaday night to Sunday Morning.




Vinod Pal :::https://www.facebook.com/vinodpal161191 ::::
Vinod Pal ::: https://plus.google.com/+VinodPal16/:::::::::::
Vinod Pal :::https://twitter.com/vinodpal161191 :::::
Vinod Pal ::::https://www.linkedin.com/in/vinodpal161191 :::
Vinod Pal ::http://vinodpal161191.blogspot.in/ :::
Vinod Pal :::: https://www.youtube.com/c/VinodPal16::::::



 Vinod Pal

 Vinod Pal

 Vinod Pal

Wednesday 4 March 2015

We Need Time

we need time, because time has no more. every moment need time but we left more time with the moment. i am trying to utilize my time according to my work in every moment but i think time is so fast. we need to go with the time continuously and utilize time in growth for success, if it's possible then everything is possible.



 Vinod Pal Facebook

 Vinod Pal

Thursday 26 February 2015

Life is either a daring adventure or nothing at all.

“The purpose of life is to live it, to taste experience to the utmost, to reach out eagerly and without fear for newer and richer experience.”
I talk big, but often don't follow through. That's my biggest problem. I don't even know what to think right now. It's about time I start to take a jump. Fuck starting to take. Just jump-over everything.
It's time to be aggressive. You've started to speak your mind, now keep going with it, but not with the intention of sparking controversy or picking a germane fight. Get your gloves on, it's time for rebirth. There IS no room for the nice guys in the history books.

Vinod Pal :::https://www.facebook.com/vinodpal161191 ::::
Vinod Pal ::: https://plus.google.com/+VinodPal16/:::::::::::
Vinod Pal :::https://twitter.com/vinodpal161191 :::::
Vinod Pal ::::https://www.linkedin.com/in/vinodpal161191 :::
Vinod Pal ::http://vinodpal161191.blogspot.in/ :::

 Vinod Pal

 Vinod Pal

 Vinod Pal

Tuesday 24 February 2015

The Reality of Life

“Just know, when you truly want success, you’ll never give up on it. No matter how bad the situation may get.”
“I don’t regret the things I’ve done, I regret the things I didn’t do when I had the chance.” 
“Accept responsibility for your life. Know that it is you who will get you where you want to go, no one else.” 

Vinod Pal ::: https://www.facebook.com/vinodpal161191 ::::
Vinod Pal ::: https://plus.google.com/+VinodPal16/ :::::::::::
Vinod Pal :::https://twitter.com/vinodpal161191 :::::
Vinod Pal :::: https://www.linkedin.com/in/vinodpal161191 :::

 Vinod Pal


Monday 23 February 2015

Enjoying Sunday in Munirka New Delhi

it's my first post in blogger. i would like to share some pics in which i am enjoying a moment with my friend in Munirka New Delhi . when i feel so stress and depress in mind, i enjoying to moving park lonely or with my friends, and feel a lot of fun there.
Vinod Pal::::::https://www.facebook.com/vinodpal161191 :::::::;
Vinod Pal::::: https://plus.google.com/+VinodPal16/ ::::::::::::::
 Vinod Pal

 Vinod Pal