php - fatal error : Call to undefined function curl_init()

标签 php linux ubuntu curl debian

<?php
$filename = "xx.gif";
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));

// $data is file data
$pvars   = array('image' => base64_encode($data), 'key' => IMGUR_API_KEY);
$timeout = 30;
$curl    = curl_init();

curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.xml');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);

$xml = curl_exec($curl);

curl_close ($curl);

var_dump($xml);
?>

我正在使用 Imgur API,但它似乎不起作用。 PHP.net 说 curl_init() 在 PHP5 中,但我的主机说不是。我怎样才能做到这一点?

最佳答案

在旧版本的 Debian 和 Ubuntu 上,您通过安装 PHP 的 Curl 扩展并重新启动网络服务器解决了这个问题。假设网络服务器是 Apache 2:

sudo apt-get install php5-curl
sudo service apache2 restart

在较新的版本中,包名称已更改:

sudo apt install php-curl

您可能需要安装更多:

sudo apt-get install curl libcurl3 libcurl3-dev;

关于php - fatal error : Call to undefined function curl_init(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4396779/

相关文章:

php - ElasticSearch查询格式错误。 Elastic-PHP客户端

php - 无法在 Linux 上启动 mysql(错误 2002 HY000)

android - 使用最新的 FFmpeg 库和 NDK 编译 Android 中的简单库时出错

php - 如何在 Ubuntu 上安装 Phar?

php - 如何更改 WooCommerce 产品页面中的 <H1> 标签

php - 你能在不先获取数组的情况下从数组中获取值吗?

php - 带有 php 的 utf-8 格式的 oracle 数据

linux - 如何解释 fio iops 日志文件?

php - raspistill 不捕获任何图像,当它由 cron 运行时

bash - 使用 sed 取消注释代码