TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-03-2008, 04:57 PM   #1 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Help 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
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 06-03-2008, 04:59 PM   #2 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Never mind, I think I found the answer here > PHP File Upload
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 06-03-2008, 05:40 PM   #3 (permalink)
The Contributor
 
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
SpYkE112 is on a distinguished road
Default

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 ;)
?>
SpYkE112 is offline  
Reply With Quote
Old 06-03-2008, 08:12 PM   #4 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

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

PHP Code:
$filename 'somereallyrandomfile.png';
$ext pathinfo($filenamePATHINFO_EXTENSION); 
Enfernikus is offline  
Reply With Quote
Old 06-03-2008, 08:14 PM   #5 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Sorry - double post.
Enfernikus is offline  
Reply With Quote
Old 06-03-2008, 08:27 PM   #6 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-03-2008, 09:17 PM   #7 (permalink)
The Contributor
 
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
SpYkE112 is on a distinguished road
Default

You could then make it into 2 variables i guess :)
But pathinfo() seems a whole lot better ;)
SpYkE112 is offline  
Reply With Quote
Old 06-04-2008, 02:34 AM   #8 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-04-2008, 09:49 AM   #9 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default

Quote:
Originally Posted by SpYkE112 View Post
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.
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Old 06-04-2008, 12:33 PM   #10 (permalink)
The Contributor
 
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
SpYkE112 is on a distinguished road
Default

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 :)
SpYkE112 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:50 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design