Unable to upload picture using PHP
Hello,
I cannot find a way to upload picture using php. I am constantly getting an error. I am not using a composer so I copied all files from cloudinary_php/src/ (github) to my project folder on my server.
My code is:
<?php
require 'Cloudinary.php';
require 'Uploader.php';
require 'Api.php';
\Cloudinary::config(array(
"cloud_name" => "***",
"api_key" => "**********",
"api_secret" => "******************"
));
\Cloudinary\Uploader::upload("myimage.PNG")
?>
I tried to flip it around a couple of times but nothing works…
I have an LAMP server and running a PHP 7.0.25-ubuntu 16.04.1
Can somebody please help me? I have been stuck for days :D, what am I missing?
-
The error:
Fatal error: Uncaught Error: Call to undefined function Cloudinary\curl_init() in /var/www/html/cloudinary_php/src/Uploader.php:343 Stack trace: #0 /var/www/html/cloudinary_php/src/Uploader.php(88): Cloudinary\Uploader::call_api('upload', Array, Array, 'myimage.PNG') #1 /var/www/html/my-account.php(14): Cloudinary\Uploader::upload('myimage.PNG') #2 {main} thrown in /var/www/html/cloudinary_php/src/Uploader.php on line 343 -
Hi @Sqiish Dev,
I saw you had created a direct ticket with us where one of my colleagues was looking into this for you. I see that you've updated that thread to let us know you were able to resolve the issue from your side.
Are you able to share a few details about what you did on the server to resolve it? It would be useful in case another user runs into a similar issue.
-
Yeah I've been able to resolve the issue.
So I found out that I was using two version's of php on my server PHP7.4 and PHP 8 i ran this command to check that,
cd /etc/php
So when i try to install curl on the server it was installing it for PHP 8. First i had to purge PHP 8 out of the server with this command
sudo apt-get purge php8.*
sudo apt-get autoclean
sudo apt-get autoremoveand i had earlier activated curl for PHP7.4 inside the php.ini file in the apache folder, to get the php.ini file you have to do this below
cd /etc/php/7.4/apache2
// when you are in the apache2 folder on the terminal run
sudo nano php.ini //this will help you edit the php.ini fileSearch for curl in the file and activate it. You can do this by removing the semincolon in front of extension and you will have this below.
extension = curl
Now that curl is active on this php verison simply use the debundled package for curl by running this command. Note that I'm using php 7.4 on the server so i will have to specify the version here.
If you dont specify the version it will install curl module for the latest version of PHP which is PHP8
$ sudo apt-get install php-curl // install's the curl module for the latest version of php
sudo apt install php7.4-curl // install's curl module for PHP 7.4After installing curl for PHP 7.4, run this command to check the specific version of curl installed
php -r 'echo curl_version()["version"] . "\n";'
And YEAH it fixed the issue 🤗. I had to install curl for the specific version of php my server is using.
Post is closed for comments.
Comments
7 comments