How to get the EXIF PHP extension working on Heroku? - php

I'm using exif data to carry captions for my images.
Using exif_read_data on localhost worked fine (with Apache on Ubuntu), but Heroku reports:
PHP Fatal error: Call to undefined function exif_read_data() in /app/path/to/files.
I'm not really sure what to do here, looking at the error message it would appear that EXIF functions are not installed/enabled on my Heroku app.
Can it be added or enabled?

You are correct that the EXIF functions are not enabled on your Heroku app.
Since the "new" PHP buildpack, all that is needed to enable extension is to define the required extensions in the composer.json file.
In the case of the EXIF that would be:
{
"require": {
"ext-exif":"*"
}
}
This is covered in the Heroku devcenter in the article for custom PHP settings.

exif extension is not enabled in your heroku environment.
You need support for exif in order to use its functions. In php.ini you will find these two lines are the ones that do it:
extension=php_mbstring.dll
extension=php_exif.dll
And of course the dlls should be available in the correct folder - For linux instead of .dll they would be .so. I am not sure how it works in heroku. Maybe you can get their tech support to check these?

Related

How to check EXIF extension is installed and enabled?

I am using Linux server. When I am trying to run exif_read_data() I am getting Fatal error: Call to undefined function exif_read_data() .
Then I contacted the server provider and they say that EXIF extension is enabled in my server. but I am getting the same error.
I have performed the Graceful Server Reboot several time
I have tried to run
if (function_exists('exif_read_data'))
and it is returning false. Also I have include phpinfo() in my page and nothing related to exif is listed in Configure Command portion.
But why did they say it is enabled for my site. Any other possibilities???
While looking phpinfo(); output finds a section like this.
exif exttension esction detail

dbase_open() can't open a .dbf file

I've installed the dbase php extension in my ubuntu server. And I see the dbase_open(...) doesn't show any error but though I provide an existing .dbf file path with mode (0 or 2) it can't open the file. No error but the returned link pointer is false. Can anyone tellme what will be the possible causes of not opening the .dbf file?
I've installed the dbase extension using this command:
[pecl install channel://pecl.php.net/get/dbase]
I've added the dbase.so extension in php.ini, restarted the server and I can see the dbase information in phpinfo().
Here are few basic information:
PHP Version 5.3.10-1
ubuntu3.10
Apache 2.0
Handler dbase extension version: 5.1.0
Any help will be appreciated.
Was *.dbf file created from visual foxpro? If so, try the following:
COPY TO filename.dbf TYPE FOX2X
I was having similar problem with you and then I tried to read dbase_open function documentation again, I found notes from jmertic at ncscredit dot com that emphasized about that thing.
As additional information related with FOX2X. FOX2X format creates a new table that can be opened in earlier versions of FoxPro (versions 2.0, 2.5, and 2.6). Other than that, you should consider differences between latest version visual foxpro field type and foxpro 2.x field type. You may read this documentation.

mime_content_type() function not defined

I am using the mime_content_type() function for file upload, it works fine on localhost however I'm encountering the following error on my live server:
Fatal error: Call to undefined function mime_content_type()
Update:
mime_content_type() is no longer deprecated, php7 has support for this function now.
Earlier version of my answer:
mime_content_type() is deprecated, probably because [fileinfo][1]
can give you those information about the file and more.
You can use finfo() like shown below,
function _mime_content_type($filename) {
$result = new finfo();
if (is_resource($result) === true) {
return $result->file($filename, FILEINFO_MIME_TYPE);
}
return false;
}
Ref: https://stackoverflow.com/a/1263977/1161412
[1]: http://php.net/manual/en/class.finfo.php
You must have the mime_magic extension on. Check your php.ini and look in phpinfo(). By the way this function has been deprecated as the PECL extension Fileinfo provides the same functionality (and more) in a much cleaner way.
Windows users must include the bundled php_fileinfo.dll DLL file in
php.ini to enable this extension.
The libmagic library is bundled with PHP, but includes PHP specific
changes. A patch against libmagic named libmagic.patch is maintained
and may be found within the PHP fileinfo extensions source.
Read more
PHP 8
Edit your php.ini file and uncomment extension=fileinfo.
Restart your HTTP server (e.g. Apache).
echo mime_content_type($path_absolute.$file);//Outputs: application/pdf
PHP 7
Edit your php.ini file and uncomment extension=php_fileinfo.dll.
Restart your HTTP server (e.g. Apache).
echo mime_content_type($path_absolute.$file);//Outputs: application/pdf
If you are on shared hosting, chances are that the fileinfo PHP extension is either not enabled or installed.
In the case where it's not enabled, navigate to the Software section of CPanel (consult documentation of your control panel if you're not using CPanel) and click Select PHP Version (or something related to that) and enable the extension by checking its box and saving your action.
If it's not installed, the extension won't be part of the PHP extensions at cPanel > Software > Select PHP Version > Extensions, edit your php.ini file and uncomment extension=php_fileinfo.dll if you're on Windows. Consult your hosting provider's docs if any of these don't work.
I changed my php version from 7.1 to 5.6 it works for me
Likely missing \php\extras\magic.mime file.

enable curl in xampp, windows

trying to enable curl in xampp 3.0.12 in windows environment.
Updated the php.ini in the php folder to enable curl, and there is no php.ini file in the apache/bin folder.
phpinfo() says:
loaded configuration file: C:\xampp\php\php.ini
curl support:enbaled
curl information: 7.24.0
and when i try to run a http_get() command php says:
Fatal error: Call to undefined function http_get()
Restarted both windows and xampp several times to update the changes.
Would be grateful for some advice, as I searched through similar topics on the web but can't get any further.
Note that the function http_get() belongs to the pecl http extension and not to the curl extension. Refer to the documentation of the curl extension to learn how you can use it to retrieve documents via http. You'll also find a lot of posts on stackoverflow
Also note, that the function file_get_contents() can be used to get documents over http in a very simple way. Although it is limited it will fit in much cases. To retrieve a page you can issue:
file_get_contents('http://www.server.com/page.html');

OpenSSL enabled but not working

I am running Apache 2.2.13 and PHP 5.2.12. Just installed PHP 5.2.12 manually (to have access to all extensions) and enabled OpenSSL. phpinfo() indicates OpenSSL is enabled and running OpenSSL 0.9.8k 25 Mar 2009.
I'm getting this error: PHP Fatal error: Call to undefined function ftp_ssl_connect().
I've seen where the PHP manual suggests 'ftp_ssl_connect() is only available if both the ftp module and the OpenSSL support is built statically into php' and further states that 'you must compile your own PHP binaries' to make it work with Windows.
I have the suspicion that phpinfo() only indicates OpenSSL as being 'enabled' because I have uncommented the line 'extension=php_openssl.dll' and have the correct dlls in the correct folders and the correct path in the environment variables. And perhaps a static build into PHP must be accomplished regardless of what phpinfo() indicates.
I believe the objective of distribution (as described above) is for dynamic extensions, but recompiling (for OpenSSL) is to encode a static extension.
ftp extension is working fine (built into PHP 5.2). I test this with the following code:
$conn_id = ftp_connect($url);
$login_result = ftp_login($conn_id, $username, $password);
ftp_close($conn_id);
Note that to check ssl, I only change ftp_connect to ftp_ssl_connect. When reaching this line, I get the PHP error above in my Apache error log file.
As the documentation states (quoting what you already quoted) :
Note: Why this function may not exist
ftp_ssl_connect() is only
available if both the ftp module and
the OpenSSL support is built
statically into php, this means that
on Windows this function will be
undefined in the official PHP builds.
To make this function available
on Windows you must compile your own
PHP binaries.
You say you installed PHP "manually" ; but this probably still means you used an "official" build from php.net -- which means you have not compiled your own PHP binaries... So, that function is not available.
There is no magic : it seems you'll have to re-compile PHP, using the right configuration options at compile-time, if you want to be able to use that function...
Here's some documentation about that : Build your own PHP on Windows -- but... good luck... i've never heard it was "simple" to compile PHP on windows, actually (it's not that hard on Linux, but Linux is maybe a bit more well suited when it comes to compilation)
A couple of other solutions :
switching to Linux for your developments (even if it's only using a Virtual Machine) -- but you might still have to recompile PHP to get that (might not be enabled by default)
just not using that function ; after all, do you know if your hosting service will provide you with it ? (If you can't use it on your production server, no need to use on your development/testing machine)

Categories