GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

View Poll Results: How complex is my code?
Not Very. 1 50.00%
A little. 0 0%
Average. 1 50.00%
Complex. 0 0%
Really complex how did you figure that out? 0 0%
Voters: 2. You may not vote on this poll

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Mar-2003, 18:04
viperman95833 viperman95833 is offline
Awaiting Email Confirmation
 
Join Date: Mar 2003
Location: Sacramento
Posts: 1
viperman95833 is an unknown quantity at this point
Question

How Do i get php to find out the file type of a file for me?


I am trying to get php to determane the file type for me so i can just put in the file name and php tells me the file type. this is the code i have so far:
<html>
<head>
<title>Dodge Viper</title></head>
<body>
<?php
$size = getimagesize ("dodge/viper/VIPER343.bmp");
if ( $size[2] == "2" ) {
$size[2]="jpg";
} else {
$size[2]="bmp";
}
echo "<img src=\"dodge/viper/VIPER343.{$size[2]}\" {$size[3]}>";
?>
</body></html>

But as you can see i have to put the file type in is there a way i can get php to find the file type out for me? Thank you
  #2  
Old 08-Mar-2003, 09:36
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
Read first then have a look here:http://dev.dave.imarc.net/fileupload/README.txt

I am not the most knowledgeable about php yet but I found this readme for a php class named fileupload which you can find here:http://dave.imarc.net/php/

Basically the readme says that the class can determine the file type so maybe you can look through the class and see how it is done. Its a bit of a longshot but it may help.
  #3  
Old 08-Mar-2003, 09:48
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Hi viperman,

I don't really see the point for you to match the image type at this point of your script.

After all, the function getimagesize() actually returns FALSE if the file it's processing is in error or not a valid image file!

I think something like this should work, unless you haven't actually told us what is it exactly that you're trying to achieve here...

PHP Code:

<html>
<head>
<title>Dodge Viper</title></head>
<body>
<?php
  $size = getimagesize( 'dodge/viper/VIPER343.bmp' );
  if( !$size ): // not a VALID image filetype
    echo "<h1>I DON'T think so!</h1>";
  else:
    echo '<img src="dodge/viper/VIPER343.bmp" '.$size[3].' />';
  endif;
?>
</body>
</html> 


n.b. Some important additions are now available with this function in PHP 4.3+
 
 

Recent GIDBlogA Week in Kuwait by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP in HTML jrobbio Web Design Forum 4 24-Jul-2003 06:05
[script] Password Protect web pages/site using PHP and MySQL JdS PHP Code Library 0 23-Jul-2003 10:02
All the big PHP script collections that matter jrobbio MySQL / PHP Forum 5 06-Jun-2003 16:14
How do I find the Unix log file route? jrobbio Web Hosting Forum 4 04-Feb-2003 07:40
VALIDATING file types on an PHP upload script? JdS MySQL / PHP Forum 0 02-Jan-2003 07:58

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:21.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.