<legend id='28jmK'><style id='28jmK'><dir id='28jmK'><q id='28jmK'></q></dir></style></legend>

<small id='28jmK'></small><noframes id='28jmK'>

  • <tfoot id='28jmK'></tfoot>

      <i id='28jmK'><tr id='28jmK'><dt id='28jmK'><q id='28jmK'><span id='28jmK'><b id='28jmK'><form id='28jmK'><ins id='28jmK'></ins><ul id='28jmK'></ul><sub id='28jmK'></sub></form><legend id='28jmK'></legend><bdo id='28jmK'><pre id='28jmK'><center id='28jmK'></center></pre></bdo></b><th id='28jmK'></th></span></q></dt></tr></i><div id='28jmK'><tfoot id='28jmK'></tfoot><dl id='28jmK'><fieldset id='28jmK'></fieldset></dl></div>
          <bdo id='28jmK'></bdo><ul id='28jmK'></ul>

        如何只允许在 php 中上传某些文件类型?

        How can I only allow certain filetypes on upload in php?(如何只允许在 php 中上传某些文件类型?)

        • <bdo id='97IWi'></bdo><ul id='97IWi'></ul>

          <small id='97IWi'></small><noframes id='97IWi'>

        • <tfoot id='97IWi'></tfoot>
            <tbody id='97IWi'></tbody>
            <legend id='97IWi'><style id='97IWi'><dir id='97IWi'><q id='97IWi'></q></dir></style></legend>

                <i id='97IWi'><tr id='97IWi'><dt id='97IWi'><q id='97IWi'><span id='97IWi'><b id='97IWi'><form id='97IWi'><ins id='97IWi'></ins><ul id='97IWi'></ul><sub id='97IWi'></sub></form><legend id='97IWi'></legend><bdo id='97IWi'><pre id='97IWi'><center id='97IWi'></center></pre></bdo></b><th id='97IWi'></th></span></q></dt></tr></i><div id='97IWi'><tfoot id='97IWi'></tfoot><dl id='97IWi'><fieldset id='97IWi'></fieldset></dl></div>
                • 本文介绍了如何只允许在 php 中上传某些文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在制作一个用户上传文件的页面.如果文件类型是其他 jpg、gif 和 pdf,我想要一个 if 语句来创建一个 $error 变量.

                  I'm making a page where the user upload a file. I want an if statement to create an $error variable if the file type is anything other jpg, gif, and pdf.

                  这是我的代码:

                  $file_type = $_FILES['foreign_character_upload']['type']; //returns the mimetype
                  
                  if(/*$file_type is anything other than jpg, gif, or pdf*/) {
                    $error_message = 'Only jpg, gif, and pdf files are allowed.';
                    $error = 'yes';
                  }
                  

                  我在构建 if 语句时遇到了困难.怎么说呢?

                  I'm having difficulty structuring the if statement. How would I say that?

                  推荐答案

                  将允许的类型放入一个数组中并使用 <代码>in_array().

                  Put the allowed types in an array and use in_array().

                  $file_type = $_FILES['foreign_character_upload']['type']; //returns the mimetype
                  
                  $allowed = array("image/jpeg", "image/gif", "application/pdf");
                  if(!in_array($file_type, $allowed)) {
                    $error_message = 'Only jpg, gif, and pdf files are allowed.';
                    $error = 'yes';
                  }
                  

                  这篇关于如何只允许在 php 中上传某些文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <legend id='w3EPm'><style id='w3EPm'><dir id='w3EPm'><q id='w3EPm'></q></dir></style></legend>

                  <i id='w3EPm'><tr id='w3EPm'><dt id='w3EPm'><q id='w3EPm'><span id='w3EPm'><b id='w3EPm'><form id='w3EPm'><ins id='w3EPm'></ins><ul id='w3EPm'></ul><sub id='w3EPm'></sub></form><legend id='w3EPm'></legend><bdo id='w3EPm'><pre id='w3EPm'><center id='w3EPm'></center></pre></bdo></b><th id='w3EPm'></th></span></q></dt></tr></i><div id='w3EPm'><tfoot id='w3EPm'></tfoot><dl id='w3EPm'><fieldset id='w3EPm'></fieldset></dl></div>

                    • <bdo id='w3EPm'></bdo><ul id='w3EPm'></ul>
                    • <tfoot id='w3EPm'></tfoot>

                          <small id='w3EPm'></small><noframes id='w3EPm'>

                              <tbody id='w3EPm'></tbody>