i need to determine the filetype of an file with php (5.3.7), no matter what filenameextension is used.
On Linux OS system i would use read the first Bytes from a file to find out the exact file type.
I think this is possible in PHP by using finfo
The Point is: my Server is not connected to the Internet, so I have to download the finfo PECL extension manually.
All that i found was this website: http://pecl.php.net/package/Fileinfo where the current finfo version is from from November 2006.
There is also an hint "his package has been superseded". But superseded by what?
If i take a look at this
http://www.php.net/manual/en/fileinfo.installation.php there is no information where i found this package.
The only thing i found there is "This extension is enabled by default as of PHP 5.3.0. " Does it mean, that this extension is part of every default >=PHP 5.3.0 installation? But if i try to use finfo commands, i get an Call to undefined function which looks like finfo is not installed, right?!
//Edit: by the way: i'm working on Linux, PHP 5.3.7
To answer my own question: I was on an wrong way for searching an new pecl file_info version.
For Linux Systems there exits an PHP package, which contains that extension, like this: php5-fileinfo-5.3.6-75.1.x86_64.rpm (depending on your Linux Distribution and PH Version)
To use fileinfo, you have install this package, like this:
#rpm -ihv php5-fileinfo-5.3.6-75.1.x86_64.rpm
Related
One of the improvements in PHP7.1 is that in Windows the readline extension is available out of the box. I'm having trouble using all of the functions though, as they don't all exist. The following code:
$functions = [
'readline_add_history',
'readline_callback_handler_install',
'readline_callback_handler_remove',
'readline_callback_read_char',
'readline_clear_history',
'readline_completion_function',
'readline_info',
'readline_list_history',
'readline_on_new_line',
'readline_read_history',
'readline_redisplay',
'readline_write_history',
'readline'
];
foreach($functions as $function) {
echo $function . (function_exists($function) ? ' exists' : ' does not exist') . PHP_EOL;
}
...produces the following output:
readline_add_history exists
readline_callback_handler_install does not exist
readline_callback_handler_remove does not exist
readline_callback_read_char does not exist
readline_clear_history exists
readline_completion_function exists
readline_info exists
readline_list_history does not exist
readline_on_new_line does not exist
readline_read_history exists
readline_redisplay does not exist
readline_write_history exists
readline exists
I can't find any reference in the PHP manual that only a subset of the readline extension's functions are available in Windows.
When I call php_info(), I get the following output:
readline
Readline Support enabled
Readline library WinEditLine
Is there some php.ini configuration setting (or CLI argument) that needs to be made in order to make all functions available? Alternately, is there some other way of making functions such as readline_callback_handler_install() available in Windows, or is the extension only half-baked?
Initially I thought that you might have been somehow falling through to an ancient PHP 5.0 which lacks those functions, but failing that I would have to guess that your PHP binary was compiled against an underlying library [or version thereof] that doesn't support the feature that those functions depend on.
Cross-referencing the list of functions that are missing with ext/readline/readline.c I would guess you're missing features corresponding to the constants/features HAVE_RL_CALLBACK_READ_CHAR and HAVE_LIBEDIT defined in ext/readline/config.m4.
TL;DR: Whoever compiled your PHP needs to figure it out. [probably]
For the record
PHP >= 7.4 to 8.1
yes:
readline_add_history
readline_clear_history
readline_completion_function
readline_info
readline_list_history
readline_read_history
readline_write_history
readline
no:
readline_callback_handler_install
readline_callback_handler_remove
readline_callback_read_char
readline_on_new_line
readline_redisplay
readline_list_history was added around during versions 7.2 and 7.3
its been 3 days of research, google and frustration to make imagick work on my XAMPP box. I can get as far on making it as php module. But it cannot detect supported formats.
As you can see, I currently have 3.1.2 installed, but I actually worked all the way from the most recent 3.4.1 and jumping from those releases tagged with stable but I just can't make it work.
When I try to run:
<?php
$handle = fopen('http://xxxxx.png', 'rb');
$img = new Imagick();
$img->readImageFile($handle);
$img->thumbnailImage(100, 0);
echo $image;
I am getting:
Uncaught exception 'ImagickException' with message 'Unable to read image from the filehandle' in xxxxx:5 Stack trace: #0 xxxxx\index.php(5): Imagick->readimagefile(Resource id #3) #1 {main} thrown in xxxxx\index.php on line 5
What I have is:
Windows 8.1 64-bit
PHP 5.6.12, x86, TS
(http://i.imgur.com/2pnneqO.png)
This is what I actually have done so far, in terms of installing it:
Download any -Thread Safe (TS) x86 package from
https://pecl.php.net/package/imagick
Extract the .zip (1) php_imagick.dll to C:\_XAMPP\php\ext (2)
Extract CORE_RL_* files to C:\_xampp\apache\bin
Download ImageMagick-7.0.1-1-Q16-x86-dll.exe from
Link
Installed it at C:\ImageMagick
Add MAGICK_HOME to environment PATH. http://i.imgur.com/jQAWl3W.png
All *_.dll file in C:\ImageMagick\modules\coders copy to
C:\_Xampp\apache\bin
All *_.dll file in C:\ImageMagick\modules\coders copy to
C:\ImageMagick\
Restart Apache via Xampp
And still can't make my PHP detect Imagick supported file formats even though they should be http://prntscr.com/b1l54u :((
Can somebody tell me what did I miss? Please?
You seem to be going a bit of a convoluted route.
The method I used to install it when I had it running was:
Download and install Ghostscript with an exe file
Download and install imagemagick with an exe file - make sure you let it add the path to the environmental variables. You may not need this step but I wanted to use Imagemagick I'm my website and on my computer anyway.
Download the Imagick dll file and put it in the recommended folder - I can not remember which now.
Uncomment the Imagick option in the php.ini file. I had
two or three php.ini files on my system and I did it in each one.
Turned off the computer and restarted. Started XAMPP and it worked.
This only worked for a couple of installs and when I upgraded the operating system I could not get it to work due to incompatible versions of php and the Imagick.dll. If I should ever want to use Imagick I would do it on my server as the hosts installed it there for me.
You can still write your code locally and test it on your production server. It is a bit of a pain but would probably be quicker/easier than trying to get Imagick working on your PC.
Out of interest I gave up with it and use Imagemagick with exec() and the command line.
I found this http://www.php.net/manual/en/class.snmp.php, but I can't find link to download this script. I tryed to search in the WEB, but the same result.
Or is the any methods with php extension to make one session and work with it?
It is in the tarball. You can download it from the official website
Take a look into it:
$ tar jtf php-5.4.13.tar.bz2 | grep snmp
php-5.4.13/ext/snmp/
php-5.4.13/ext/snmp/config.m4
php-5.4.13/ext/snmp/config.w32
php-5.4.13/ext/snmp/CREDITS
php-5.4.13/ext/snmp/php_snmp.h
php-5.4.13/ext/snmp/snmp.c
php-5.4.13/ext/snmp/snmp.dsp
php-5.4.13/ext/snmp/tests/
php-5.4.13/ext/snmp/tests/bug60749.phpt
php-5.4.13/ext/snmp/tests/bug64124.phpt
php-5.4.13/ext/snmp/tests/clean.inc
php-5.4.13/ext/snmp/tests/generic_timeout_error.phpt
php-5.4.13/ext/snmp/tests/ipv6.phpt
php-5.4.13/ext/snmp/tests/README
php-5.4.13/ext/snmp/tests/skipif.inc
php-5.4.13/ext/snmp/tests/snmp-object-errno-errstr.phpt
php-5.4.13/ext/snmp/tests/snmp-object-error.phpt
php-5.4.13/ext/snmp/tests/snmp-object-properties.phpt
php-5.4.13/ext/snmp/tests/snmp-object-setSecurity_error.phpt
php-5.4.13/ext/snmp/tests/snmp-object.phpt
php-5.4.13/ext/snmp/tests/snmp2_get.phpt
php-5.4.13/ext/snmp/tests/snmp2_getnext.phpt
php-5.4.13/ext/snmp/tests/snmp2_real_walk.phpt
php-5.4.13/ext/snmp/tests/snmp2_set-nomib.phpt
php-5.4.13/ext/snmp/tests/snmp2_set.phpt
php-5.4.13/ext/snmp/tests/snmp2_walk.phpt
php-5.4.13/ext/snmp/tests/snmp3-error.phpt
php-5.4.13/ext/snmp/tests/snmp3.phpt
php-5.4.13/ext/snmp/tests/snmp_get_quick_print.phpt
php-5.4.13/ext/snmp/tests/snmp_get_valueretrieval.phpt
php-5.4.13/ext/snmp/tests/snmp_getvalue.phpt
php-5.4.13/ext/snmp/tests/snmp_include.inc
php-5.4.13/ext/snmp/tests/snmp_read_mib.phpt
php-5.4.13/ext/snmp/tests/snmp_set_enum_print.phpt
php-5.4.13/ext/snmp/tests/snmp_set_oid_output_format.phpt
php-5.4.13/ext/snmp/tests/snmpd.conf
php-5.4.13/ext/snmp/tests/snmpget.phpt
php-5.4.13/ext/snmp/tests/snmpgetnext.phpt
php-5.4.13/ext/snmp/tests/snmprealwalk.phpt
php-5.4.13/ext/snmp/tests/snmpset-nomib.phpt
php-5.4.13/ext/snmp/tests/snmpset.phpt
php-5.4.13/ext/snmp/tests/snmpwalk.phpt
php-5.4.13/ext/snmp/tests/wrong_hostname.phpt
The "SNMP" class (introduced in PHP 5.4) is not a "script"; rather, it is an extension that is either compiled into PHP or shipped as a module that can be enabled or disabled. I suspect that either (1) you are using an older version of PHP, or (2) you do not have the SNMP extension installed or enabled.
I would like to develop an extension which depends on an external shared library. My current problem is that I am not being able to link this shared library to my extension.
My development environment is Fedora Linux x64 + PHP 5.4. This external shared library is a proprietary one, I just have its headers (.h) and .so files (for 32 and 64 bits).
The project's current config.m4 file is as follows:
PHP_ARG_WITH(projectname,
[Whether to enable ProjectName support],
[ --with-projectname enable ProjectName support])
if test "$PHP_PROJECTNAME" != "no"; then
PHP_ADD_LIBRARY_WITH_PATH(externallib, lib64, PROJECTNAME_SHARED_LIBADD)
AC_DEFINE(HAVE_PROJECTNAME, 1, [Whether you have ProjectName])
PHP_NEW_EXTENSION(projectname, projectname.c, $ext_shared)
fi
The problem here is every time I run ./configure --with-projectname the generated makefile does not have any reference to the library, plus the compiled .so file fails (obviously).
It would also be useful if I had a way to determine the right lib directory according to the architecture.
You've included the library, but looks you're missing the actual link option. I haven't done this in the longest time, but I think something like the following should work.
EXTERNAL_LIB="blahLibName"
LIB_LINK_CMD="-L/usr/local/lib -l$EXTERNAL_LIB"
PHP_ADD_LIBRARY_WITH_PATH(externallib, lib64, PROJECTNAME_SHARED_LIBADD)
PHP_EVAL_LIBLINE($LIB_LINK_CMD, PROJECTNAME_SHARED_LIBADD)
The syntax here might not be right at all, but you definitely need the PHP_EVAL_LIBLINE.
i'm trying to create a zip script based on what I've found here but I seem to be getting a Fatal error: Class 'ZipArchive' not found error on the new ZipArchive(); function.
Researching this it seems that this is usually due to the way PHP is compiled. I have a shared hosting account, so i've not configured any of this stuff...and I assume that I can't make any changes to the build. Out of interest I took a look in my phpinfo() and I found some things that looked associated:
PHP Version 5.2.6
BZip2 Support Enabled <--maybe not so relevant
ZLib Support enabled
Stream Wrapper support compress.zlib://
Stream Filter support zlib.inflate, zlib.deflate
Compiled Version 1.1.4
Linked Version 1.1.4
I'm not entirly sure if any of this means that I have the ability to create zips.
For further info (although I don't think it's relivent) here's my script so far....this is untested mind you as I can't get pased this Class not found error.
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
//the string "file1" is the name we're assigning the file in the archive
$zip->addFile('show1.jpg', 'file1.jpg');
$zip->addFile('show2.jpg', 'file2.jpg');
$zip->addFile('show3.jpg', 'file3.jpg');
$zip->addFile('show4.jpg', 'file4.jpg');
$zip->addFile('show5.jpg', 'file5.jpg');
$zip->addFile('show6.jpg', 'file6.jpg');
// echo $zip->file(); //this sends the compressed archive to the output buffer instead of writing it to a file.
$zip->close();
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="' . $file.'"');
readfile($file);
unlink($file);
So my question(s) really are:
Am I doing anything in my script to cause this error?
Does any of that stuff from my phpinfo() mean I should be able to create zip files, ..if not what should I be looking for in there that will let me know if i have the capability.
It looks like this ZLib is some soft of library, but I've got no idea if it does what I want it do, or even how to use it....this is a bit of a hunch, but if it can help me create zip files can anyone point me in the right direction of how to use it?
Thanks in advance.
Dan
ZipArchive is apparently not compiled into PHP by default. You need to either recompile it with the '--with-zip=' option or simply install it via PECL.
Here is the manual page explaining the different methods:
http://www.php.net/manual/en/zip.installation.php
While zlib is an important compression library, it sounds like you're missing the zip extension itself. It looks like you got your information from phpinfo -- look for the exact words "zip extension." If you can't find them, you don't have it installed, and thus can not use the functions and methods provided by it.
You could try dl("zip.so"); as last resort. But that extension is rarely built as external module. You might be able to find it downloadable somewhere, or even compile it by hand from the PHP sources or http://pecl.php.net/package/zip using pecl build
Otherwise you will have to look for an alternative. http://pear.php.net/package/Archive_Zip comes to mind.
If you have upgrade php version or zip extension is not there
So you have to install it .
1) Open terminal
2) sudo apt-get install php7.0-zip
3) sudo service apache2 restart