<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 中上传某些文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)
                  <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>