<legend id='PzZXc'><style id='PzZXc'><dir id='PzZXc'><q id='PzZXc'></q></dir></style></legend>

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

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

    <bdo id='PzZXc'></bdo><ul id='PzZXc'></ul>
  • <tfoot id='PzZXc'></tfoot>
      1. $_FILES 字段 'tmp_name' 对 .JPG 文件扩展名没有

        时间:2023-05-20
        • <bdo id='jBH2a'></bdo><ul id='jBH2a'></ul>
            <legend id='jBH2a'><style id='jBH2a'><dir id='jBH2a'><q id='jBH2a'></q></dir></style></legend>

          • <tfoot id='jBH2a'></tfoot>
              <tbody id='jBH2a'></tbody>

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

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

                  本文介绍了$_FILES 字段 'tmp_name' 对 .JPG 文件扩展名没有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  当我测试带有此扩展名 .JPG 的图像文件时,我正在制作上传脚本,我不知道 jpg 或 jpeg 之间有什么区别,但似乎 $_FILES 无法识别这种文件类型.

                  我读过几个线程,说 $_FILES 在 mime 类型方面并不可靠,所以我决定使用 php 的 mime 类型函数 mime_content_type(),php 的 getimagesize(), pathinfo(),虽然路径信息返回文件名和类型,但我需要不存在的文件路径,所有函数都通过 $_FILES['file']['tmp_name'] 作为参数.

                  所以当我决定上传一个图像文件时出现了这个问题,例如 sample.JPG,我认为这些文件中的大部分都是来自相机的原始文件 <-- 这就是我的想法,但更重要的是我可以上传 .JPG、.jpg、jpeg、.png.除了 .JPG 之外,所有这些都可以正常工作.

                  主要问题是在上传.JPG 时$_FILES 中的字段['tmp_name'] 没有值.

                  遇到此问题的任何人都请分享您的解决方法或您是如何做到的"之类的事情.

                  解决方案

                  如果 $_FILES[$field]['tmp_name'] 为空,则文件尚未上传.您应该查看 $_FILES[$field]['error'] 以了解原因.

                  FWIW,据我所知,$_FILES[] 中的 MIME 类型是由浏览器提供的.

                  更新:这里有一些处理所有文件上传错误的代码:

                   $message = '上传文件时出错';开关($_FILES['newfile']['error']){情况 UPLOAD_ERR_OK:$消息=假;;休息;案例 UPLOAD_ERR_INI_SIZE:案例 UPLOAD_ERR_FORM_SIZE:$message .= ' - 文件太大('.get_max_upload().'字节限制).';休息;案例 UPLOAD_ERR_PARTIAL:$message .=' - 文件上传未完成.';休息;案例 UPLOAD_ERR_NO_FILE:$message .=' - 上传的文件长度为零.';休息;默认:$message .= ' - 内部错误 #'.$_FILES['newfile']['error'];休息;}如果(!$消息){if(!is_uploaded_file($_FILES['newfile']['tmp_name'])) {$message = '上传文件时出错 - 未知错误.';} 别的 {//让我们看看我们是否可以移动文件...$dest .='/'.$this_file;if( !move_uploaded_file($_FILES['newfile']['tmp_name'], $dest) ) {//没有错误支持,所以我们可以看到潜在的错误.$message = '上传文件时出错 - 无法保存上传(这可能是 '.$dest.' 中的权限问题)';} 别的 {$message = '文件上传正常.';}}}

                  i was making an upload script when i tested an image file wit this extension .JPG, i don't know whats the difference between jpg or jpeg, but it seems that $_FILES don't recognize this file type.

                  I've read several threads that $_FILES ins't that reliable when it comes to mime type, so i decided to used the php's mime type function mime_content_type(), php's getimagesize(), pathinfo(), though pathinfo returns a file name, and type, but i need the path of the file which is NOT present, all of the functions are being passed with $_FILES['file']['tmp_name'] as parameters.

                  So this problem came up when i decided to upload an image file e.g sample.JPG, i think most of this files are raw from the camera <-- that's what i think though but nevertheless what is more important is that i can upload them .JPG, .jpg, jpeg, .png. all of them works fine except for .JPG.

                  Main problem is that field ['tmp_name'] in $_FILES has no values when .JPG is to be uploaded.

                  Any of you guys who have encountered this problem please do share your workaround or "how did you do it" kind of thing.

                  解决方案

                  If $_FILES[$field]['tmp_name'] is empty then the file hasn't been uploaded. You should look at $_FILES[$field]['error'] to see why.

                  FWIW, and as far as I understand it, the mime-type in $_FILES[] is provided by the browser.

                  Update: here is a bit of potted code to handle all file upload errors:

                          $message = 'Error uploading file';
                          switch( $_FILES['newfile']['error'] ) {
                              case UPLOAD_ERR_OK:
                                  $message = false;;
                                  break;
                              case UPLOAD_ERR_INI_SIZE:
                              case UPLOAD_ERR_FORM_SIZE:
                                  $message .= ' - file too large (limit of '.get_max_upload().' bytes).';
                                  break;
                              case UPLOAD_ERR_PARTIAL:
                                  $message .= ' - file upload was not completed.';
                                  break;
                              case UPLOAD_ERR_NO_FILE:
                                  $message .= ' - zero-length file uploaded.';
                                  break;
                              default:
                                  $message .= ' - internal error #'.$_FILES['newfile']['error'];
                                  break;
                          }
                          if( !$message ) {
                              if( !is_uploaded_file($_FILES['newfile']['tmp_name']) ) {
                                  $message = 'Error uploading file - unknown error.';
                              } else {
                                  // Let's see if we can move the file...
                                  $dest .= '/'.$this_file;
                                  if( !move_uploaded_file($_FILES['newfile']['tmp_name'], $dest) ) { // No error supporession so we can see the underlying error.
                                      $message = 'Error uploading file - could not save upload (this will probably be a permissions problem in '.$dest.')';
                                  } else {
                                      $message = 'File uploaded okay.';
                                  }
                              }
                          }
                  

                  这篇关于$_FILES 字段 'tmp_name' 对 .JPG 文件扩展名没有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用PHP处理多个文件上传 下一篇:统计和限制上传文件的数量(HTML文件输入)

                  相关文章

                  最新文章

                  <tfoot id='eeCN5'></tfoot>

                1. <legend id='eeCN5'><style id='eeCN5'><dir id='eeCN5'><q id='eeCN5'></q></dir></style></legend>

                  1. <i id='eeCN5'><tr id='eeCN5'><dt id='eeCN5'><q id='eeCN5'><span id='eeCN5'><b id='eeCN5'><form id='eeCN5'><ins id='eeCN5'></ins><ul id='eeCN5'></ul><sub id='eeCN5'></sub></form><legend id='eeCN5'></legend><bdo id='eeCN5'><pre id='eeCN5'><center id='eeCN5'></center></pre></bdo></b><th id='eeCN5'></th></span></q></dt></tr></i><div id='eeCN5'><tfoot id='eeCN5'></tfoot><dl id='eeCN5'><fieldset id='eeCN5'></fieldset></dl></div>
                    • <bdo id='eeCN5'></bdo><ul id='eeCN5'></ul>
                    1. <small id='eeCN5'></small><noframes id='eeCN5'>