Reputation: 15959
<?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);
?>
I'm playing with the Imgur API, but it doesn't seems to work. PHP.net says that curl_init()
is in PHP5, but my host says it isn't. How can I make this work?
Upvotes: 73
Views: 189480
Reputation: 143
For Windows this worked for me. Go to php.ini
file and remove the comment from the following lines
extension=bz2
extension=curl
Just remove the ;
before each line to uncomment. Restart the server and this error will go away
Upvotes: 0
Reputation: 2594
For Ubuntu
Install Curl extension for PHP & restart apache server.
sudo apt-get install php5-curl
sudo service apache2 restart
For Windows
Problem arises because of not including the lib_curl.dll to PHP.
also load following extension if not working,so those extension in php.ini
or remove comment if already exist in php.ini
file then remove comment.
extension=php_bz2.dll
extension=php_curl.dll
extension=php_dba.dll
Now restart apache server. If you get an error "Unable to Load php_curl.dll", copy SSLEAY32.PHP, libEAY32.dll (OpenSSL) Libraries to the System32 folder.
Upvotes: 14
Reputation: 2366
for php 7.0 on ubuntu use
sudo apt-get install php7.0-curl
And finally,
sudo service apache2 restart
or
sudo service nginx restart
Upvotes: 6
Reputation: 1248
Experienced this on ubuntu 16.04 running PHP 7.1.14. To resolve,first put this in a script and execute. It will return true if curl is installed and enabled,otherwise, it will return false.
<?php
var_dump(extension_loaded('curl'));
?>
If it returns false, run
sudo apt-get install php7.1-curl
And finally,
sudo service apache2 restart
After the restart, the script will return true and hopefully, your error should be resolved.
Upvotes: 3
Reputation: 13411
On old versions of Debian and Ubuntu, you solved this by installing the Curl extension for PHP, and restarting the webserver. Assuming the webserver is Apache 2:
sudo apt-get install php5-curl
sudo service apache2 restart
On newer versions, the package name as changed:
sudo apt install php-curl
It's possible you'll need to install more:
sudo apt-get install curl libcurl3 libcurl3-dev;
Upvotes: 132
Reputation: 1749
do this
sudo apt-get install php-curl
and restart server
sudo service apache2 restart
Upvotes: 4
Reputation: 1
After installation of PHP.
Move to Windows\system32 folder: libssh2.dll, php_curl.dll, ssleay32.dll, libeay32.dll
Move to Apache24\bin folder libssh2.dll
Then uncomment extension=php_curl.dll in php.ini
Upvotes: -2
Reputation: 935
There is solution with all necessary details for Windows 7 x64:
http://www.youtube.com/watch?v=7qNTi1sEfE8
It is in French, but you can understand everything! I solved same problem, even don't speak French. :-)
Many answers forget to mention that you need to add new version of php_curl.dll file from this location: http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/
I added new version of php_curl.dll from archive php_curl-5.4.3-VC9-x64.zip to folders: C:\wamp\bin\php\php5.4.3\ext and C:\Windows\System32 and everything was fine!
Upvotes: 2
Reputation: 3628
Don't have enough reputation to comment yet. Using Ubuntu and a simple:
sudo apt-get install php5-curl
sudo /etc/init.d/apache2 restart
Did NOT work for me.
For some reason curl.so
was installed in a location not picked up by default. I checked the extension_dir
in my php.ini and copied over the curl.so
to my extension_dir
cp /usr/lib/php5/20090626/curl.so /usr/local/lib/php/extensions/no-debug-non-zts-20090626
Hope this helps someone, adjust your path locations accordingly.
Upvotes: 14
Reputation: 141
$ch = curl_init('http://api.imgur.com/2/upload.xml'); //initialising our url
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //used for https headers
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //used for https headers
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($pvars));
//the value we post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //waiting for reponse, default value in php is zero ie, curls normally do not wait for a response
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
$output = curl_exec($ch); //the real execution
curl_close($ch);
echo $output;
Try this code. I am not sure about it. But i used it to send xml data to a remote url.
Upvotes: -3
Reputation: 21531
curl is an extension that needs to be installed, it's got nothing to do with the PHP version.
http://www.php.net/manual/en/curl.setup.php
Upvotes: 42