<?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?
The curl_init() function will initialize a new session and return a cURL handle. curl_exec($ch) function should be called after initialize a cURL session and all the options for the session are set. Its purpose is simply to execute the predefined CURL session (given by ch).
php // Script to test if the CURL extension is installed on this server // Define function to test function _is_curl_installed() { if (in_array ('curl', get_loaded_extensions())) { return true; } else { return false; } } // Ouput text to user based on test if (_is_curl_installed()) { echo "cURL is <span style=\"color: ...
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;
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With