TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Getting a file extention (http://www.talkphp.com/absolute-beginners/2889-getting-file-extention.html)

ETbyrne 06-03-2008 04:57 PM

Getting a file extention
 
I am wondering how you get the file name and exstention from a $_FILES field because this doesn't work:

PHP Code:

$filename $_FILES['myinputbox']; 

Thanks,
Evan Byrne

ETbyrne 06-03-2008 04:59 PM

Never mind, I think I found the answer here > PHP File Upload

SpYkE112 06-03-2008 05:40 PM

You could do like this as an alternative, but it is stupid to rely on mime types and extentions.

But:
PHP Code:

<?php
$myFile 
'/path/to/my.file';

$ext end(explode('.'$myFile));

echo(
$ext);

// Outputs: file
// Or it should ;)
?>


Enfernikus 06-03-2008 08:12 PM

I'd like to point out the pathfile function here's an example

PHP Code:

$filename 'somereallyrandomfile.png';
$ext pathinfo($filenamePATHINFO_EXTENSION); 


Enfernikus 06-03-2008 08:14 PM

Sorry - double post.

Wildhoney 06-03-2008 08:27 PM

I've used Enfernikus' way ever since I found about it. That and my other ways, apart from regular expressions, contain a function within a function, and PHP when in strict mode doesn't like that :-(

SpYkE112 06-03-2008 09:17 PM

You could then make it into 2 variables i guess :)
But pathinfo() seems a whole lot better ;)

Wildhoney 06-04-2008 02:34 AM

The second argument wouldn't need to be added to these functions if PHP supported this:

php Code:
$ext = pathinfo($filename)['ext'];

It's exasperating!

Jmz 06-04-2008 09:49 AM

Quote:

Originally Posted by SpYkE112 (Post 15144)
You could do like this as an alternative, but it is stupid to rely on mime types and extentions.

But:
PHP Code:

<?php
$myFile 
'/path/to/my.file';

$ext end(explode('.'$myFile));

echo(
$ext);

// Outputs: file
// Or it should ;)
?>



What should you use to determine the file type if you dont use mime types and file extensions?

I've been having some problems creating a secure, image only file upload script. Sometimes it decides the mime type of a jpg file isn't acceptable.

SpYkE112 06-04-2008 12:33 PM

Well, frankly i don't know, but if it is images only, then you could probaly run it through some GD, but try and take a look at KalleLoad - Powered by KalleLoad it's an open source project, by Kalle here at TalkPHP :)


All times are GMT. The time now is 06:30 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0