Rectangle 27 10

In order to read data from microsoft excel 2007 by codeigniter just create a helper function excel_helper.php and add the following in:

require_once APPPATH.'libraries/phpexcel/PHPExcel.php';
      require_once APPPATH.'libraries/phpexcel/PHPExcel/IOFactory.php';
      in controller add the following code to read spread sheet by active sheet
     //initialize php excel first  
     ob_end_clean();
     //define cachemethod
     $cacheMethod   = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
     $cacheSettings = array('memoryCacheSize' => '20MB');
     //set php excel settings
     PHPExcel_Settings::setCacheStorageMethod(
            $cacheMethod,$cacheSettings
          );

    $arrayLabel = array("A","B","C","D","E");
    //=== set object reader
    $objectReader = PHPExcel_IOFactory::createReader('Excel2007');
    $objectReader->setReadDataOnly(true);

    $objPHPExcel = $objectReader->load("./forms/test.xlsx");
    $objWorksheet = $objPHPExcel->setActiveSheetIndexbyName('Sheet1');

    $starting = 1;
    $end      = 3;
    for($i = $starting;$i<=$end; $i++)
    {

       for($j=0;$j<count($arrayLabel);$j++)
       {
           //== display each cell value
           echo $objWorksheet->getCell($arrayLabel[$j].$i)->getValue();
       }
    }
     //or dump data
     $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
     var_dump($sheetData);

     //see also the following link
     http://blog.mayflower.de/561-Import-and-export-data-using-PHPExcel.html
     ----------- import in another style around 5000 records ------
     $this->benchmark->mark('code_start');
    //=== change php ini limits. =====
    $cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_phpTemp;
    $cacheSettings = array( ' memoryCacheSize ' => '50MB');
    PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
    //==== create excel object of reader
    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    //$objReader->setReadDataOnly(true);
    //==== load forms tashkil where the file exists
    $objPHPExcel = $objReader->load("./forms/5000records.xlsx");
    //==== set active sheet to read data
    $worksheet  = $objPHPExcel->setActiveSheetIndexbyName('Sheet1');


    $highestRow         = $worksheet->getHighestRow(); // e.g. 10
    $highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
    $nrColumns          = ord($highestColumn) - 64;
    $worksheetTitle     = $worksheet->getTitle();

    echo "<br>The worksheet ".$worksheetTitle." has ";
    echo $nrColumns . ' columns (A-' . $highestColumn . ') ';
    echo ' and ' . $highestRow . ' row.';
    echo '<br>Data: <table border="1"><tr>';
    //----- loop from all rows -----
    for ($row = 1; $row <= $highestRow; ++ $row) 
    {
        echo '<tr>';
        echo "<td>".$row."</td>";
        //--- read each excel column for each row ----
        for ($col = 0; $col < $highestColumnIndex; ++ $col) 
        {
            if($row == 1)
            {
                // show column name with the title
                 //----- get value ----
                $cell = $worksheet->getCellByColumnAndRow($col, $row);
                $val = $cell->getValue();
                //$dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
                echo '<td>' . $val ."(".$row." X ".$col.")".'</td>';
            }
            else
            {
                if($col == 9)
                {
                    //----- get value ----
                    $cell = $worksheet->getCellByColumnAndRow($col, $row);
                    $val = $cell->getValue();
                    //$dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
                    echo '<td>zone ' . $val .'</td>';
                }
                else if($col == 13)
                {
                    $date = PHPExcel_Shared_Date::ExcelToPHPObject($worksheet->getCellByColumnAndRow($col, $row)->getValue())->format('Y-m-d');
                    echo '<td>' .dateprovider($date,'dr') .'</td>';
                }
                else
                {
                     //----- get value ----
                    $cell = $worksheet->getCellByColumnAndRow($col, $row);
                    $val = $cell->getValue();
                    //$dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
                    echo '<td>' . $val .'</td>';
                }
            }
        }
        echo '</tr>';
    }
    echo '</table>';
    $this->benchmark->mark('code_end');

    echo "Total time:".$this->benchmark->elapsed_time('code_start', 'code_end');     
    $this->load->view("error");

php - how to use phpexcel to read data and insert into database? - Sta...

php phpexcel
Rectangle 27 7

CI sessions offers some extra functionality; such as auto regenerating the session id every given amount of time (for security), IP address tracking, and flashdata (session data that's cleared after it's read once).

CI's session mechanism stores all the data in a cookie. PHP's native session mechanism is stored server side. Each have it's advantages/disadvantages. Cookies can only hold 4KB of data, so if your storing large amounts of data in session PHP native sessions might be better.

If you decide to you want to use native PHP sessions use:

Session Hybrid uses native PHP sessions, can store session data in the default CI db, is a drop-in replacement for CIs session class, and only requires one file to be rewritten.

Side note: If you choose to stay with CI's sessions

Thanks, for the info. I have decided to migrate back to PHP sessions, because they are easier to use. (and allow manual sesseion_regeneration)

php - Which session library should I use with CodeIgniter? - Stack Ove...

php arrays session codeigniter
Rectangle 27 7

If you store sessions in databases, check that garbage collecting of sessions in PHP is really activated (it's not the case on Debian-like distributions, they decided to garbage sessions with their own cron and altered the php.ini so that it never launch any gc, so check the session.gc_probability and session.gc_divisor). The main problem of sessionstorage in database is that it means a lot of write queries and a lot of conflicting access in the database. This is a great way of stressing a database server like MySQL. So IMHO using another solution is better, this keeps your read/write ratio in a better web-database way.

You could also keep the file storage system and simply share the file directory between servers with NFS. Alter the session.save_path setting to use something other than /tmp. But NFS is by definition not the fastest wy of using a disk. Prefer memcached or mongodb for fast access.

If the only thing you need to share between the server is authentification, then instead of sharing the real session storage you could share authentification credentials. Like the OpenId system in SO, it's what we call an SSO, for the web part you have several solutions, from OpenId to CAS, and others. If the data is merged on the client side (ajax, ESI-gate) then you do not really need a common session data storage on server-side. This will avoid having 3 of your 5 impacted web application writing data in the shared session in the same time. Other session sharing techniques (database, NFS, even memcached) are mostly used to share your data between several servers because Load Balancing tools can put your sequential HTTP request from one server to another, but if you really mean parallel gathering of data you should really study SSO.

php - How to manage a single PHP5 session on multiple apache servers? ...

php apache session multiserver
Rectangle 27 17

Having spoken to MailChimp, the certificate they're still (Jan 2016) using for compatibility reasons, they told me is the GTE CyberTrust Global Root (note GTE was bought by Digicert), so you don't need to replace the entire bundle, just add or force PHP to read this certificate:

(note you'll get an 'insecure connection' warning if you try and load that in Firefox, for hopefully obvious reasons you can add an exception.)

It's in standard .crt format, which is what you need. Guide to certificate formats

You didn't specify what the server was but here's how to add an extra one on Linux without having to replace an entire bundle etc:

On Debian/Ubuntu, certificates live in /etc/ssl/certs/

  • Copy and paste the signature into a new file in that directory, e.g. mailchimp-legacy.crt
  • run sudo c_rehash /etc/ssl/certs - What's going on here: c_rehash calculates a short hash of each certificate and creates a symlink from that to the original .pem or .crt file. Basically it's a quick lookup table for openssl - openssl will perform the hash as well and look for the symlink, rather than having to have a database of certificate names or open every file in turn to find the right one.
ls -lh *.0 | grep 'mailchimp-legacy.crt'

You should see something like this:

lrwxrwxrwx 1 root root 20 Feb 13 14:17 4d654d1d.0 -> mailchimp-legacy.crt
lrwxrwxrwx 1 root root 20 Feb 13 14:17 c692a373.0 -> mailchimp-legacy.crt

Alternatively: On Debian, there's also a file called /etc/ca-certificates.conf and the exclamation mark in the line !mozilla/GTE_CyberTrust_Global_Root.crt indicates not to use that one. I believe it's possible to put a copy of the certificate with that name under /usr/share/ca-certificates/mozilla and run sudo update-ca-certificates, but it seems to me it be likely to be removed again when the package & config file are next updated.

Remember to remove any workarounds you were using - e.g. - old CA bundles in your certificate directory - anywhere you override CURLOPT_CAINFO in your PHP - an openssl.cainfo line in your php.ini

Check your application works correctly. I didn't need to restart PHP or my webserver, the change was instant. Worth using apt-get update/upgrade to check you have the most recently certificate packages.

Here's a way to verify SSL connection (and verification) to a specific server from the command line:

echo GET | openssl s_client -CApath /etc/ssl/certs/ -connect us3.api.mailchimp.com:443 2>&1

Monitoring: (updated) MailChimp's v2.0 API (deprecated) has an endpoint called 'helper/ping' which returns some text to indicate the API status - useful as an automated test of API health and that your certificates are all still working. If you're using v3.0, they recommend using the API Root Resource and appending ?fields=account_name if you don't actually need to check any of the data.

Someone asked in the comments if this was related to Heartbleed. No. Heartbleed is an openssl vulnerability related to eavesdropping on data in RAM. Mozilla removed GTE CyberTrust (twice) because they wanted to remove all 1024-bit root certificates - research has suggested a nation state could break a 1024-bit prime.

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Thank you! Been banging my head against a wall for a few days on this!

Is there a way to accomplish this temporarily on OSX without compromising security?

SSL errors using MailChimp's API - Stack Overflow

ssl mailchimp
Rectangle 27 7

session_register() is not required and may be causing a problem here. Read the docs on session_register() - it is intended to assign session variables using existing variables.

and from here:

Well, session_register() tells PHP that a certain global variable should be considered a session variable. That means that at the end of the script's execution (which is when session data writes usually occur), the resulting value of that global variable will be written using the current enabled session handlers.

I think this is the problem that you are experiencing. At the end of the script execution the session variable gets over-written.

Yeah, session_register() has been deprecated for quite a while, it definitely shouldn't be used any more. I don't know whether it's causing this specific issue, but it shouldn't be in that code regardless.

Interesting. I'm working from an introductory PHP/SQL book that's copyright '07, and the code is pretty much a direct quote. Unfortunately, remvoing the session_register() lines doesn't seem to solve the problem. Thanks very much for the information.

PHP Session Variables Not Preserved - Stack Overflow

php session session-variables
Rectangle 27 7

session_register() is not required and may be causing a problem here. Read the docs on session_register() - it is intended to assign session variables using existing variables.

and from here:

Well, session_register() tells PHP that a certain global variable should be considered a session variable. That means that at the end of the script's execution (which is when session data writes usually occur), the resulting value of that global variable will be written using the current enabled session handlers.

I think this is the problem that you are experiencing. At the end of the script execution the session variable gets over-written.

Yeah, session_register() has been deprecated for quite a while, it definitely shouldn't be used any more. I don't know whether it's causing this specific issue, but it shouldn't be in that code regardless.

Interesting. I'm working from an introductory PHP/SQL book that's copyright '07, and the code is pretty much a direct quote. Unfortunately, remvoing the session_register() lines doesn't seem to solve the problem. Thanks very much for the information.

PHP Session Variables Not Preserved - Stack Overflow

php session session-variables
Rectangle 27 7

session_register() is not required and may be causing a problem here. Read the docs on session_register() - it is intended to assign session variables using existing variables.

and from here:

Well, session_register() tells PHP that a certain global variable should be considered a session variable. That means that at the end of the script's execution (which is when session data writes usually occur), the resulting value of that global variable will be written using the current enabled session handlers.

I think this is the problem that you are experiencing. At the end of the script execution the session variable gets over-written.

Yeah, session_register() has been deprecated for quite a while, it definitely shouldn't be used any more. I don't know whether it's causing this specific issue, but it shouldn't be in that code regardless.

Interesting. I'm working from an introductory PHP/SQL book that's copyright '07, and the code is pretty much a direct quote. Unfortunately, remvoing the session_register() lines doesn't seem to solve the problem. Thanks very much for the information.

PHP Session Variables Not Preserved - Stack Overflow

php session session-variables
Rectangle 27 101

You are POSTing the json incorrectly -- but even if it were correct, you would not be able to test using print_r($_POST) (read why here). Instead, on your second page, you can nab the incoming request using file_get_contents("php://input"), which will contain the POSTed json. To view the received data in a more readable format, try this:

echo '<pre>'.print_r(json_decode(file_get_contents("php://input")),1).'</pre>';

In your code, you are indicating Content-Type:application/json, but you are not json-encoding all of the POST data -- only the value of the "customer" POST field. Instead, do something like this:

$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode( array( "customer"=> $data ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
echo "<pre>$result</pre>";

great, worked like a charm!

Hah! I was struggling as to why I wasnt receiving the data via $_POST. The issue was that I had to use php://input like you said. Thanks.

where was this answer when I was looking for it all week last week? Now I find it way after I had to figure out myself!

How to POST JSON Data With PHP cURL? - Stack Overflow

php json rest curl
Rectangle 27 99

You are POSTing the json incorrectly -- but even if it were correct, you would not be able to test using print_r($_POST) (read why here). Instead, on your second page, you can nab the incoming request using file_get_contents("php://input"), which will contain the POSTed json. To view the received data in a more readable format, try this:

echo '<pre>'.print_r(json_decode(file_get_contents("php://input")),1).'</pre>';

In your code, you are indicating Content-Type:application/json, but you are not json-encoding all of the POST data -- only the value of the "customer" POST field. Instead, do something like this:

$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode( array( "customer"=> $data ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
echo "<pre>$result</pre>";

great, worked like a charm!

Hah! I was struggling as to why I wasnt receiving the data via $_POST. The issue was that I had to use php://input like you said. Thanks.

where was this answer when I was looking for it all week last week? Now I find it way after I had to figure out myself!

How to POST JSON Data With PHP cURL? - Stack Overflow

php json rest curl
Rectangle 27 1

If you read the Codeigniter Class Reference setuserdata expects the second argument to be a value, that in case first argument is a key, hence the error.

with the Codeigniter way, you won't be able to achieve what you want as it uses:

$result=array('name'=>'john doe');
$this->session->set_userdata($result);
$this->session->set_userdata('name','john doe');
echo $this->session->userdata(['name']);

on the other hand using vanilla php $_SESSION you can achieve it like so:

$_SESSION['user']=$result;
echo $_SESSION['user']['name'];

this is due to your ENVIRONMENT setting, as you have error_reporting limited at the production (live) server. This is set in your root index.php.

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
define('ENVIRONMENT', 'production');

Actually $this->session->set_userdata('name', $name); works, but the function userdata() only accepts one argument and expects it to be a string

/**
 * Userdata (fetch)
 *
 * Legacy CI_Session compatibility method
 *
 * @param   string  $key    Session data key
 * @return  mixed   Session data value or NULL if not found
 */
public function userdata($key = NULL)
{
    if (isset($key))
    {
        return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL;
    }
    elseif (empty($_SESSION))
    {
        return array();
    }

    $userdata = array();
    $_exclude = array_merge(
        array('__ci_vars'),
        $this->get_flash_keys(),
        $this->get_temp_keys()
    );

    foreach (array_keys($_SESSION) as $key)
    {
        if ( ! in_array($key, $_exclude, TRUE))
        {
            $userdata[$key] = $_SESSION[$key];
        }
    }

    return $userdata;
}

No, I already tried this. And set_userdata can have the first parameter as name. I was using it with success.

@ShanilSoni please see my updated answer, if you use php $_SESSION you can resolve your problem. No error on live server is definitely your Environment setting, I've just checked it.

No, I tried everything what all suggested but nothing was working. Finally, I found the issue, CI 3.1.6 was not supporting PHP 7.1, when I moved back to 5.6, it started saving the session. Thank you so much for your help.

I'm clueless then why it was not working in my local environment. I have been facing this issue for 15 days now. When I switched back, it started working somwhow.

php - Sessions not working in localhost but work in live server (Codei...

php codeigniter session
Rectangle 27 1

php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives.

The important part is "POST reqest".

This means, when you say http://www.example.com/tests/testtest.php?name=what, you send a GET request and not a POST request. Therefore, there is no request body, and you cannot read anything through php://input.

To read form input passed as URL parameters, you may use the global $_GET variable.

When you use a POST request, you usually use the global $_POST array, instead of reading the request body manually through php://input.

You may also consider $_REQUEST, if you don't care if it is a POST or GET request. Although, be aware of What's wrong with using $_REQUEST[]?

Do you have any other method I can use to make it possible to send a data thru url parameter?

Yes, this is what GET parameters are for, see $_GET

You may also want to look into $_POST instead of reading the request body through php://input.

file_get_contents('php://input') returns empty when sending thru url p...

php
Rectangle 27 1

php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives.

The important part is "POST reqest".

This means, when you say http://www.example.com/tests/testtest.php?name=what, you send a GET request and not a POST request. Therefore, there is no request body, and you cannot read anything through php://input.

To read form input passed as URL parameters, you may use the global $_GET variable.

When you use a POST request, you usually use the global $_POST array, instead of reading the request body manually through php://input.

You may also consider $_REQUEST, if you don't care if it is a POST or GET request. Although, be aware of What's wrong with using $_REQUEST[]?

Do you have any other method I can use to make it possible to send a data thru url parameter?

Yes, this is what GET parameters are for, see $_GET

You may also want to look into $_POST instead of reading the request body through php://input.

file_get_contents('php://input') returns empty when sending thru url p...

php
Rectangle 27 4

Yes you can, just use javascript to get the file, making sure you read the file as a data URL. Parse out the stuff before base64 to actually get the base 64 encoded data and then if you are using php or really any back end language you can decode the base 64 data and save into a file like shown below

Javascript:
var reader = new FileReader();
reader.onloadend = function ()
{
  dataToBeSent = reader.result.split("base64,")[1];
  $.post(url, {data:dataToBeSent});
}
reader.readAsDataURL(this.files[0]);


PHP:
    file_put_contents('my.pdf', base64_decode($_POST["data"]));

Of course you will probably want to do some validation like checking which file type you are dealing with and stuff like that but this is the idea.

file_put_contents($fname, file_get_contents($_POST['data'])); file_get_contents deals with the decoding and data:// header

javascript - jQuery Ajax File Upload - Stack Overflow

javascript jquery ajax post file-upload
Rectangle 27 4

Yes you can, just use javascript to get the file, making sure you read the file as a data URL. Parse out the stuff before base64 to actually get the base 64 encoded data and then if you are using php or really any back end language you can decode the base 64 data and save into a file like shown below

Javascript:
var reader = new FileReader();
reader.onloadend = function ()
{
  dataToBeSent = reader.result.split("base64,")[1];
  $.post(url, {data:dataToBeSent});
}
reader.readAsDataURL(this.files[0]);


PHP:
    file_put_contents('my.pdf', base64_decode($_POST["data"]));

Of course you will probably want to do some validation like checking which file type you are dealing with and stuff like that but this is the idea.

file_put_contents($fname, file_get_contents($_POST['data'])); file_get_contents deals with the decoding and data:// header

javascript - jQuery Ajax File Upload - Stack Overflow

javascript jquery ajax post file-upload
Rectangle 27 4

Yes you can, just use javascript to get the file, making sure you read the file as a data URL. Parse out the stuff before base64 to actually get the base 64 encoded data and then if you are using php or really any back end language you can decode the base 64 data and save into a file like shown below

Javascript:
var reader = new FileReader();
reader.onloadend = function ()
{
  dataToBeSent = reader.result.split("base64,")[1];
  $.post(url, {data:dataToBeSent});
}
reader.readAsDataURL(this.files[0]);


PHP:
    file_put_contents('my.pdf', base64_decode($_POST["data"]));

Of course you will probably want to do some validation like checking which file type you are dealing with and stuff like that but this is the idea.

file_put_contents($fname, file_get_contents($_POST['data'])); file_get_contents deals with the decoding and data:// header

javascript - jQuery Ajax File Upload - Stack Overflow

javascript jquery ajax post file-upload
Rectangle 27 4

Yes you can, just use javascript to get the file, making sure you read the file as a data URL. Parse out the stuff before base64 to actually get the base 64 encoded data and then if you are using php or really any back end language you can decode the base 64 data and save into a file like shown below

Javascript:
var reader = new FileReader();
reader.onloadend = function ()
{
  dataToBeSent = reader.result.split("base64,")[1];
  $.post(url, {data:dataToBeSent});
}
reader.readAsDataURL(this.files[0]);


PHP:
    file_put_contents('my.pdf', base64_decode($_POST["data"]));

Of course you will probably want to do some validation like checking which file type you are dealing with and stuff like that but this is the idea.

file_put_contents($fname, file_get_contents($_POST['data'])); file_get_contents deals with the decoding and data:// header

javascript - jQuery Ajax File Upload - Stack Overflow

javascript jquery ajax post file-upload
Rectangle 27 4

Yes you can, just use javascript to get the file, making sure you read the file as a data URL. Parse out the stuff before base64 to actually get the base 64 encoded data and then if you are using php or really any back end language you can decode the base 64 data and save into a file like shown below

Javascript:
var reader = new FileReader();
reader.onloadend = function ()
{
  dataToBeSent = reader.result.split("base64,")[1];
  $.post(url, {data:dataToBeSent});
}
reader.readAsDataURL(this.files[0]);


PHP:
    file_put_contents('my.pdf', base64_decode($_POST["data"]));

Of course you will probably want to do some validation like checking which file type you are dealing with and stuff like that but this is the idea.

file_put_contents($fname, file_get_contents($_POST['data'])); file_get_contents deals with the decoding and data:// header

javascript - jQuery Ajax File Upload - Stack Overflow

javascript jquery ajax post file-upload
Rectangle 27 4

Yes you can, just use javascript to get the file, making sure you read the file as a data URL. Parse out the stuff before base64 to actually get the base 64 encoded data and then if you are using php or really any back end language you can decode the base 64 data and save into a file like shown below

Javascript:
var reader = new FileReader();
reader.onloadend = function ()
{
  dataToBeSent = reader.result.split("base64,")[1];
  $.post(url, {data:dataToBeSent});
}
reader.readAsDataURL(this.files[0]);


PHP:
    file_put_contents('my.pdf', base64_decode($_POST["data"]));

Of course you will probably want to do some validation like checking which file type you are dealing with and stuff like that but this is the idea.

file_put_contents($fname, file_get_contents($_POST['data'])); file_get_contents deals with the decoding and data:// header

javascript - jQuery Ajax File Upload - Stack Overflow

javascript jquery ajax post file-upload
Rectangle 27 4

Yes you can, just use javascript to get the file, making sure you read the file as a data URL. Parse out the stuff before base64 to actually get the base 64 encoded data and then if you are using php or really any back end language you can decode the base 64 data and save into a file like shown below

Javascript:
var reader = new FileReader();
reader.onloadend = function ()
{
  dataToBeSent = reader.result.split("base64,")[1];
  $.post(url, {data:dataToBeSent});
}
reader.readAsDataURL(this.files[0]);


PHP:
    file_put_contents('my.pdf', base64_decode($_POST["data"]));

Of course you will probably want to do some validation like checking which file type you are dealing with and stuff like that but this is the idea.

file_put_contents($fname, file_get_contents($_POST['data'])); file_get_contents deals with the decoding and data:// header

javascript - jQuery Ajax File Upload - Stack Overflow

javascript jquery ajax post file-upload
Rectangle 27 4

Yes you can, just use javascript to get the file, making sure you read the file as a data URL. Parse out the stuff before base64 to actually get the base 64 encoded data and then if you are using php or really any back end language you can decode the base 64 data and save into a file like shown below

Javascript:
var reader = new FileReader();
reader.onloadend = function ()
{
  dataToBeSent = reader.result.split("base64,")[1];
  $.post(url, {data:dataToBeSent});
}
reader.readAsDataURL(this.files[0]);


PHP:
    file_put_contents('my.pdf', base64_decode($_POST["data"]));

Of course you will probably want to do some validation like checking which file type you are dealing with and stuff like that but this is the idea.

file_put_contents($fname, file_get_contents($_POST['data'])); file_get_contents deals with the decoding and data:// header

javascript - jQuery Ajax File Upload - Stack Overflow

javascript jquery ajax post file-upload