using explode to determin filetypes
Moderator: General Moderators
using explode to determin filetypes
hello again
i'm building a upload website and now i need to make sure that only zip files are being uploaded.
setting mime types in the forms doesn't work correctly and i can get the hang of the php
get_mime type thing so i'm going to use explode for this.
for this i have a few questions:
1. I'm going to use explode at every . how do i reverse the ouput so that the filetype comes first?
2. How do i extract the extension from the string or array?
3. Any other ways of determening the file types?
thanks in advance
ps. sorry for the horrid spelling
i'm building a upload website and now i need to make sure that only zip files are being uploaded.
setting mime types in the forms doesn't work correctly and i can get the hang of the php
get_mime type thing so i'm going to use explode for this.
for this i have a few questions:
1. I'm going to use explode at every . how do i reverse the ouput so that the filetype comes first?
2. How do i extract the extension from the string or array?
3. Any other ways of determening the file types?
thanks in advance
ps. sorry for the horrid spelling
Have you tried the ZIP functions? http://uk.php.net/zip ... zip_open() might be a good one to look at.
have looked at it and it's not what i'm looking for.
allow me to be a little bit clearer:
i'm making a file upload website for distribution of large files to various clients of my company.
akin to megaupload and all those others. The employees are only allowed to upload zip files i want to check in the
part of the site that the file is being move to the server if it's a file type that's being allowed.
and the file that the clients need is a zip file that needs to be downloaded. they are not allowed to open
the files with the use of our website.
example of what i want with the explode function:
file name: ryuuka.the.man.upload.zip
this should output: ryuuka the man upload zip
what i want is this : zip upload man the zip
now i want to take zip out and perform a loop like this:
if ($extension = zip)
{
//everything uploads etc
}
if ($extension != zip)
{
// not allowed to upload
}
hope this is of more use
allow me to be a little bit clearer:
i'm making a file upload website for distribution of large files to various clients of my company.
akin to megaupload and all those others. The employees are only allowed to upload zip files i want to check in the
part of the site that the file is being move to the server if it's a file type that's being allowed.
and the file that the clients need is a zip file that needs to be downloaded. they are not allowed to open
the files with the use of our website.
example of what i want with the explode function:
file name: ryuuka.the.man.upload.zip
Code: Select all
explode(".", ryuuka.the.man.upload.zip);this should output: ryuuka the man upload zip
what i want is this : zip upload man the zip
now i want to take zip out and perform a loop like this:
if ($extension = zip)
{
//everything uploads etc
}
if ($extension != zip)
{
// not allowed to upload
}
hope this is of more use
Well, array_reverse() will reverse the array so that the last element is first. Or you can just look at $array[count($array)-1] if you don't want to reverse it. Or you could use strtolower(strrchr($filename, ".")); to get everything after the last period. The problem with that though is that it relies on the extension being right. If I make a file called nasty_file_containing_a_virus.exe, rename it to nasty_file_containing_a_virus.zip, your code will happily accept it thinking that it's a zip file. If you examine the file itself (eg, see if zip_open() can open it) then you'll know if it's a zip file or not.
-
mcog_esteban
- Forum Contributor
- Posts: 127
- Joined: Tue Dec 30, 2003 3:28 pm
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
mime_content_type() uses the filename.
As parameterfeyd wrote:mime_content_type() uses the filename.
-
brendandonhue
- Forum Commoner
- Posts: 71
- Joined: Mon Sep 25, 2006 3:21 pm
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
No it's not.feyd wrote:It uses magic.mime which is based on the filename. Not the composition of the file.
I don't see any filename information here.mime.magic wrote:0 leshort 0x602 application/x-alan-adventure-game
0 string TADS application/x-tads-game
0 short 0420 application/x-executable-file
0 short 0421 application/x-executable-file
0 leshort 0603 application/x-executable-file
0 string Core\001 application/x-executable-file
0 string AMANDA:\ TAPESTART\ DATE application/x-amanda-header
0 belong 0x000003f3 application/x-executable-file
0 belong 0x000003e7 application/x-library-file
0 belong 0x000001b3 video/mpeg
0 belong 0x000001ba video/mpeg
0 beshort&0xfff0 0xfff0 audio/mpeg
4 leshort 0xAF11 video/fli
4 leshort 0xAF12 video/flc
[...]
Rename a zip archive to e.g. test.jpg and mime_content_type will still return application/zip based on
mime.magic wrote:0 string PK\003\004 application/zip
Last edited by volka on Thu Jan 04, 2007 12:12 pm, edited 1 time in total.