duanqiu9104 2013-01-27 01:56
浏览 108
已采纳

如何与in_array进行不区分大小写的匹配? [关闭]

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?

  • 写回答

2条回答 默认 最新

  • dongxuan8227 2013-01-27 01:58
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝