if we have
$allowimg = array('gif','bmp','jpg','png','jpeg','tif','tiff','tga','psd');
and want to make upload center with it if we put this code
if(in_array($filetype,$allowimg)){
//pic
$error = 0;
$filedoc = 'pic';
}
else{ echo 'bad file type!';}
if user upload my.PNG
its run Else cuz PNG is not == png for php
can anyone help me with this?
and how to secure from file uploads?
$filename = explode('.',$nn);
is ok? so what if user upload
my.pic.jpg?
Just strtolower()
the file type!
if(in_array(strtolower($filetype),$allowimg)){
//pic
$error = 0;
$filedoc = 'pic';
}
else{ echo 'bad file type!';}
Part two of your question
While I suggest you to make a new question for each one rather than a set of questions in a single task, here is how I usually get the file name from the string.
$ext = pathinfo($filename, PATHINFO_EXTENSION);
pathinfo()
function gives information of the path thrown to it. You can optionally get a string with just what you want by specifying it in the second parameter.
$ext
now contains the extension of the file: jpg
(could be JPG
JPg
, etc. Use the code above to fix that).
if(in_array(strtolower($filetype),$allowimg)){