php fileinfo help needed

php fileinfo help needed

am 22.01.2008 10:36:42 von Bob

I am having trouble getting the PHP PECL fileinfo component to work. I
am using Cakephp 1.2, XAMPP in WIndows Vista environment.

I have the following code:
$file = "C:\xampp\htdocs\app\webroot\pics\file.jpg";

$handle = finfo_open(FILEINFO_COMPRESS,'c:/magic');//
FILEINFO_COMPRESS,"c:/magic");
if (!$handle) {
echo "Opening fileinfo database failed";

}

$mime_type = finfo_file($handle,$file);

I get the following output:
Opening fileinfo database failed
Warning (2): finfo_file(): supplied argument is not a valid file_info
resource [APP\controllers\users_controller.php, line 198]

I put the magic.mime file in the C:\ directory. I also added the
extension=php_fileinfo.dll line in the php.ini file.

Thanks in advance

Re: php fileinfo help needed

am 22.01.2008 11:42:39 von quamis

On Jan 22, 11:36 am, bob wrote:
> I am having trouble getting the PHP PECL fileinfo component to work. I
> am using Cakephp 1.2, XAMPP in WIndows Vista environment.
>
> I have the following code:
> $file = "C:\xampp\htdocs\app\webroot\pics\file.jpg";
>
> $handle = finfo_open(FILEINFO_COMPRESS,'c:/magic');//
> FILEINFO_COMPRESS,"c:/magic");
> if (!$handle) {
> echo "Opening fileinfo database failed";
>
> }
>
> $mime_type = finfo_file($handle,$file);
>
> I get the following output:
> Opening fileinfo database failed
> Warning (2): finfo_file(): supplied argument is not a valid file_info
> resource [APP\controllers\users_controller.php, line 198]
>
> I put the magic.mime file in the C:\ directory. I also added the
> extension=php_fileinfo.dll line in the php.ini file.
>
> Thanks in advance

I`m not sure how its on windows..but 'c:/magic' ?? shouldn`t it be 'c:
\magic'? From what i see here, $handle is either false, or null.
Either case $handle should be a resource id, not null.

From the manual:
"A .mime and/or .mgc suffix is added if needed."


Return Values
Returns a magic database resource on success or FALSE on
failure. ..... so your call to finfo_open failed:)

Re: php fileinfo help needed

am 22.01.2008 13:13:08 von luiheidsgoeroe

On Tue, 22 Jan 2008 10:36:42 +0100, bob wrote:

> I am having trouble getting the PHP PECL fileinfo component to work. I=

> am using Cakephp 1.2, XAMPP in WIndows Vista environment.
>
> I have the following code:
> $file =3D "C:\xampp\htdocs\app\webroot\pics\file.jpg";

Either use '/' or '\\' as path seperator.
-- =

Rik Wasmus

Re: php fileinfo help needed

am 22.01.2008 18:03:31 von AnrDaemon

Greetings, _q_u_a_m_i_s's.
In reply to Your message dated Tuesday, January 22, 2008, 13:42:39,

> I`m not sure how its on windows..but 'c:/magic' ?? shouldn`t it be
> 'c:\magic'?

No. There is absolutely no difference between '\' and '/' when working with
filesystem under DOS or Windows.


--
Sincerely Yours, AnrDaemon

Re: php fileinfo help needed

am 22.01.2008 18:09:54 von AnrDaemon

Greetings, bob.
In reply to Your message dated Tuesday, January 22, 2008, 12:36:42,

> I have the following code:
> $file = "C:\xampp\htdocs\app\webroot\pics\file.jpg";

Try to print() this variable value and You'll see Your problem.
Rule to work with strings:
Do NOT use double-quotes unless You absolutely sure You need them.
So, either
$file = 'C:\xampp\htdocs\app\webroot\pics\file.jpg';
or (as rick said) this way
$file = "C:/xampp/htdocs/app/webroot/pics/file.jpg";

But much safer and portable way is to use forward-slashes even with
single-quoted string.

$file = 'C:/xampp/htdocs/app/webroot/pics/file.jpg';


--
Sincerely Yours, AnrDaemon