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.
Related
I have a function in php that needs to connect to ftp using ftp_ssl_connect. Iam using windows seven and as per the answers from google I need to rebuild the php to include the ssl functions. Now my question if is there a way to enable ssl on Windows without rebuilding php? Or is there a donwloadable version where ssl already included for windows?
thanks
From PHP doc:
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.
Emphasis mine.
However, I've downloaded PHP binary for windows from official php.net and I noticed there's a specific DLL (ext/php_openssl.dll) for openssl. It means maybe it's not necessary rebuild PHP in order to get openssl working. Just remember add an entry for the dll in php.ini file.
It should be something like this:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"
...
extension=php_openssl.dll
NOTE
I haven't tested the above case.
As of PHP 7.0, the core FTP extension on Windows is by default built with OpenSSL support. In the earlier PHP versions, while SSL support is possible, it is not provided with the standard builds for various reasons. The only solution for PHP 5 is to make a custom build of PHP, while the standard PHP 7.0 builds on windows.php.net provide the ftp_ssl_connect() function.
Thanks.
I am using godaddy VPS having php version of 5.4.33.
Now I want to enable php_fileinfo extension in ini file to avoid the error
Fatal error: Class 'finfo' not found in my php script.
To enable I did the following:
1. open WebHost Manager.
2. Go to Service Configuration
3. Go to PHP Configuration Editor
4. search extension directive and fill as `fileinfo.so` in the input box and save
5. restart all services.
6. create a file in the server with the code <?php echo phpinfo();?>. but in that I am not finding any `fileinfo` status. It indicates still it is not enabled.
Could you please help me why this is not configured still?
Thanks in advance.
You could do that with EasyApache:
In the PHP version selection page, please choose version 5.3 or above, as FileInfo is available to version 5.3.X or above only.
Then, select Exhaustive Option List
If you don't know anything about EasyApache, you could read the documentation: https://documentation.cpanel.net/display/EA/EasyApache
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?
I installed memcached by reading this article on Windows7 but unfortunately i keep getting error Fatal error: Class 'Memcache' not found in D:\xampp\htdocs\test\memcache\test.php on line 2
Line 2: $memcache = new Memcache;
Win7 64, Xampp Installed. I am using net start "memcached Server" on command line but it says service is already started.
Some other info which may help;
On php.ini file:
extension=php_memcache.dll
[Memcache]
memcache.allow_failover = 1
memcache.max_failover_attempts=20
memcache.chunk_size =8192
memcache.default_port = 11211
Update: phpinfo(); show dll is not loaded. Tried several different dll files so far, didn't work. Also dll is located correct. It is in the right folder as it seems.
(P.S. Some may think there are possible duplicates about this topic but there is only 1 person who followed the same instructions and had same error in SO. That question has no answer or solution since march.)
I found the working dll files for PHP 5.4.4
I don't knowhow stable they are but they work for sure. Credits goes to this link.
http://x32.elijst.nl/php_memcache-5.4-nts-vc9-x86.zip
http://x32.elijst.nl/php_memcache-5.4-vc9-x86.zip
It is the 2.2.5.0 version, I noticed after compiling it (for PHP
5.4.4).
Please note that it is not 2.2.6 but works. I also mirrored them in my own FTP.
Mirror links:
http://mustafabugra.com/resim/php_memcache-5.4-vc9-x86.zip
http://mustafabugra.com/resim/php_memcache-5.4-nts-vc9-x86.zip
Add this to your php.ini:
extension="php_memcache.dll"
and restart apache
Memcached just uses standard text interface so its possible to use it without the module.
// connect
$link = fsockopen($host,$port,$errno,$errst,$timeout);
// set
$data = sprintf("set %s 0 %s %s\r\n%s\r\n",
$key,$expire,strlen($value),$value);
fwrite($link,$data);
$result = trim(fgets($link));
if ($result == 'ERROR') {
// :(
}
// get
$data = sprintf("get %s\r\n",$key);
fwrite($link,$data);
$line = rtrim(fgets($link));
if ($line != 'END') {
return rtrim(fgets($link));
}
So i have looked now for a solution. Here you can download some compiled extensions.
http://downloads.php.net/pierre/
The problem is that at the moment there is no memcache extension for PHP 5.4. this is the problem why your extension could not be loaded. You need the extension for the correct PHP version and Tead Safe for Windows.
So the easiest way is to work with PHP 5.3 if you need the extension.
The newest version of memcache is the version 3.0.6 but its a beta version you can see it here.
http://pecl.php.net/package/memcache
You could try to take the beta version and compile it with your windows system. But its a lot of work.
Also problem can be in loading another version of php module somewhere in apache .conf files. Need to check duplicated "LoadModule php..." directives and if that module compiled to correct version of apache.
It seems sound simply, but not when you have several versions of php on one machine :)
Or it can be SElinux problem too.
xampp windows version is 32bit ,you must be use 32bit memcache.dll
I hole that would be useful for you!
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)