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 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!