Page 1 of 1
upload form limiting
Posted: Thu Oct 24, 2002 6:41 pm
by SL-Cowsrule
Im not sure if i can use MIME types for this, but if you know how to limit the kind/type of file that can be uploded, please post here.
Thanks,
CoW
Posted: Fri Oct 25, 2002 1:01 pm
by daynah
I think the best thing to do is to check the file type after it's been uploaded temporily.
You can check the array $HTTP_POST_FILES['userfile']['tmp_name'] if you are using php.
Something like
Code: Select all
<?php
if ($HTTP_POST_FILESї'imagefile']ї'type'] == "image/gif")
{
// do something here
}
else
{
echo 'sorry, wrong file type!';
}
?>
You can read an article about it here:
http://www.phpfreaks.com/tutorials/36/0.php
Posted: Sat Oct 26, 2002 11:49 pm
by volka
http://www.w3.org/TR/html4/interact/for ... def-accept
i.e.
Code: Select all
<input type="file" accept="text/*" name="ufile" />
will accept all text-files (text/plain, text/html, ....).
But that's courtesy of the browser, so a server-side check is mandatory to be sure
Posted: Sun Oct 27, 2002 2:03 am
by Takuma
Or you could check the extension
Code: Select all
<?php
if(substr($file,-1,-3) == "gif") {
echo "It's a GIF file";
}
?>
Posted: Sun Oct 27, 2002 2:08 am
by volka
Or you could check the extension
that's exactly what I hate windows for

And sometimes file-extensions are longer than 3 chars (i.e. index.html)
Posted: Sun Oct 27, 2002 2:12 am
by Takuma
but you'll know that cos you're checking it (so it'll become "tml").
Posted: Sun Oct 27, 2002 2:14 am
by volka
only as example:
what ever 'Procedure Builder' is

it uses .tml as extension for "Export for Task Manager file"
http://www.aiai.ed.ac.uk/~entprise/ente ... BUIL94.htm 
Posted: Sun Oct 27, 2002 2:16 am
by Takuma
ok how about changing the code then?
substr($file,-1,-4);
Then for 3 character exntesion add "." at the start and it'll be alright for 4 character ones.

Posted: Sun Oct 27, 2002 2:21 am
by volka
naaa, I'll wait for
mime-magic.
Until than I use
Code: Select all
substr($fname, strrpos($fname, '.'))
Posted: Sun Oct 27, 2002 4:49 am
by Takuma
that's clever script that is... Never thought of it. Thanks I can use that for my script

Posted: Sun Oct 27, 2002 7:11 am
by mydimension
why not just use strrchr()
Code: Select all
$str = "some.weird.file.name";
$result = strrchr($str, ".");
//$result now equals ".name"
Posted: Sun Oct 27, 2002 7:25 am
by volka
because I come from the C++-world and some php-return-values are uncommon to me
