douzhang8144 2016-07-06 07:16
浏览 67
已采纳

PHP只接受一种要上传的扩展类型。 该文件是未知的扩展类型

this my first question here. I am new to PHP, but I have been searching for an answer for this question for about an hour, and have had no luck. Maybe I am just no reading it correctly, but I hope you guys can help me. I am trying to let people only upload one file type to my website. That file type is a .osk . I am not sure if I am doing this correctly, but I have it set up like this

$types = array ('application/osk'); 

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

$target_path = "skins/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 


if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path, $types)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>

I get an error whenever I submit that specific file type. And I also get an error if I submit anything else, but that is expected. Sorry if the code is a mess. I am new to this as I said before. But, I would love it if someone could help me figure out this.

  • 写回答

1条回答 默认 最新

  • douqiao3930 2016-07-06 07:27
    关注

    Try this code

    $file_parts = pathinfo($_FILES['uploadedfile']['name']);
    // Check file is osk
    if($file_parts['extension'] == 'osk')
    {
      // move file
      if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path))
      {
        echo "Uploaded";
      }
      else
      {
        echo "File was not uploaded";
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line