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 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形