11

I am integrating Dropbox into my PHP based website. When i try to run the following code. i got this Fatal error: Call to undefined function readline() on the last line.

require_once "dropbox-sdk/Dropbox/autoload.php";
use \Dropbox as dbx;
$appInfo = dbx\AppInfo::loadFromJsonFile("app-info.json");

echo "<pre>";
print_r($appInfo);
echo "</pre>";

$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");

echo "<pre>";
print_r($webAuth);
echo "</pre>";

$authorizeUrl = $webAuth->start();
echo "1. Go to: " . $authorizeUrl . "\n<br>";
echo "2. Click \"Allow\" (you might have to log in first).\n<br>";
echo "3. Copy the authorization code.\n<br>";
$authCode = \trim(\readline("Enter the authorization code here: "));

I have come through different forum where people said it will work in Command line , But I don't understand how? Any idea ?

bcmcfc
  • 25,966
  • 29
  • 109
  • 181
M Fayyaz
  • 131
  • 1
  • 2
  • 7

3 Answers3

23

Or just use this to simulate it

if(!function_exists("readline")) {
    function readline($prompt = null){
        if($prompt){
            echo $prompt;
        }
        $fp = fopen("php://stdin","r");
        $line = rtrim(fgets($fp, 1024));
        return $line;
    }
}
Chris Gibb
  • 845
  • 8
  • 11
4

readline() is for running on the command line not via the web browser.

To check you have it installed on your server, type:

php -i | grep Configure

Probably, you have not installed it and you should compile it yourself or ask your hosting admin to if they allow this.

darrenp
  • 4,265
  • 2
  • 26
  • 22
David
  • 373
  • 5
  • 23
3

Just had this issue on Ubuntu.

Found this answer: https://askubuntu.com/a/264329/166

The solution in this scenario was to install the package php5-readline.

Community
  • 1
  • 1
bcmcfc
  • 25,966
  • 29
  • 109
  • 181