<bdo id='68YhD'></bdo><ul id='68YhD'></ul>
<tfoot id='68YhD'></tfoot>

      1. <small id='68YhD'></small><noframes id='68YhD'>

        <legend id='68YhD'><style id='68YhD'><dir id='68YhD'><q id='68YhD'></q></dir></style></legend>
      2. <i id='68YhD'><tr id='68YhD'><dt id='68YhD'><q id='68YhD'><span id='68YhD'><b id='68YhD'><form id='68YhD'><ins id='68YhD'></ins><ul id='68YhD'></ul><sub id='68YhD'></sub></form><legend id='68YhD'></legend><bdo id='68YhD'><pre id='68YhD'><center id='68YhD'></center></pre></bdo></b><th id='68YhD'></th></span></q></dt></tr></i><div id='68YhD'><tfoot id='68YhD'></tfoot><dl id='68YhD'><fieldset id='68YhD'></fieldset></dl></div>

        嗯,这是新的.无法从智能手机上传照片?

        Well this is new. Uploading photos from smartphones not possible?(嗯,这是新的.无法从智能手机上传照片?)
        <i id='hULAi'><tr id='hULAi'><dt id='hULAi'><q id='hULAi'><span id='hULAi'><b id='hULAi'><form id='hULAi'><ins id='hULAi'></ins><ul id='hULAi'></ul><sub id='hULAi'></sub></form><legend id='hULAi'></legend><bdo id='hULAi'><pre id='hULAi'><center id='hULAi'></center></pre></bdo></b><th id='hULAi'></th></span></q></dt></tr></i><div id='hULAi'><tfoot id='hULAi'></tfoot><dl id='hULAi'><fieldset id='hULAi'></fieldset></dl></div>

          <tbody id='hULAi'></tbody>

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

        <legend id='hULAi'><style id='hULAi'><dir id='hULAi'><q id='hULAi'></q></dir></style></legend>
          <tfoot id='hULAi'></tfoot>
              • <bdo id='hULAi'></bdo><ul id='hULAi'></ul>
                  本文介绍了嗯,这是新的.无法从智能手机上传照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我正在创建一个响应式网站,可以选择将图像上传到页面.php 脚本基本上是调整图像大小并在数据库中存储拇指文件路径.原始图像和拇指图像也存储在网站文件夹中.我正在使用 GD 库.

                  So I am creating a responsive website that has the option of uploading images to the page. The php script basically resizes the the image and stores a thumb file path in the database. The original image and thumb image are also stored in the website folder. I am using GD library.

                  不管怎样,我只是在做一个从我的 iPhone 上传照片到网站的测试.它确实上传了图像.但是它有两个问题.

                  Anyhow, I was just doing a test of uploading a photo from my iphone to the website. It does upload the image. However there are two issues with it.

                  1. 上传照片的时间太长了.
                  2. 上传完成后,照片是横向的.如果照片是纵向的,它将作为横向上传.很奇怪.

                  谁能帮我解决这两个问题?

                  Can anyone help me with these two issues?

                  更新代码

                  if (isset($_FILES['image'])) {
                  
                      if (empty($_FILES['image']['name'])) {
                  
                              ?><div class="add-errors">Please choose an image!</div><?php 
                  
                      }   else {
                  
                  
                          function getOrientedImage($imagePath){
                              $image = imagecreatefromstring(file_get_contents($imagePath));
                              $exif = exif_read_data($imagePath);
                              if(!empty($exif['Orientation'])) {
                                  switch($exif['Orientation']) {
                                      case 8:
                                          $image = imagerotate($image,90,0);
                                          break;
                                      case 3:
                                          $image = imagerotate($image,180,0);
                                          break;
                                      case 6:
                                          $image = imagerotate($image,-90,0);
                                          break;
                                  }
                              }
                              return $image;
                          }
                  
                          $name       =   $_FILES['image']['name'];
                          $temp       =   $_FILES['image']['tmp_name'];
                          $type       =   $_FILES['image']['type'];
                          $size       =   $_FILES['image']['size'];
                          $ext        =   strtolower(end(explode('.', $name)));
                          $size2      =   getimagesize($temp);
                          $width      =   $size2[0];
                          $height     =   $size2[1];
                          $upload     =   md5( rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 ));
                  
                          // Restrictions for uploading
                          $maxwidth   =   6000;
                          $maxheight  =   6000;
                          $allowed    =   array('image/jpeg', 'image/jpg', 'image/png', 'image/gif');
                  
                          // Recognizing the extension
                          switch($type){
                  
                              // Image/Jpeg
                              case 'image/jpeg':
                                      $ext= '.jpeg';
                              break;
                  
                              // Image/Jpg
                              case 'image/jpg':
                                      $ext= '.jpg';
                              break;
                  
                              // Image/png
                              case 'image/png':
                                      $ext= '.png';
                              break;
                  
                              // Image/gif
                              case 'image/gif':
                                      $ext= '.gif';
                              break;
                          }
                  
                          // upload variables
                          $path           =   $userDir . $upload . $ext;
                          $thumb_path     =   $userDir . 'thumb_' . $upload . $ext;
                  
                          // check if extension is allowed.
                          if (in_array($type, $allowed)) {
                  
                              // Checking if the resolution is FULLHD or under this resolution.
                              if ($width <= $maxwidth && $height <= $maxheight) {
                                  if ($size <= 5242880) {
                  
                                      // check the shape of the image
                                      if ($width == $height) {$shape = 1;}
                                      if ($width > $height) {$shape = 2;}
                                      if ($width < $height) {$shape = 2;}
                  
                                      //Adjusting the resize script on shape.
                                      switch($shape) {
                  
                                          // Code to resize a square image.
                                          case 1:
                                              $newwidth =     690;
                                              $newheight =    690;
                                          break;
                  
                                          // Code to resize a tall image
                                          case 2:
                                              $newwidth   =   690;
                                              $ratio      =   $newwidth / $width;
                                              $newheight  =   round($height * $ratio);
                  
                                          break;
                  
                                      }
                  
                                      // Resizing according to extension.
                                      switch ($type) {
                  
                                          // Image/Jpeg   
                                          case 'image/jpeg';
                                              $img =      getOrientedImage($temp);
                                              $thumb =    imagecreatetruecolor($newwidth, $newheight);
                                                          imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
                                                          imagejpeg($thumb, $thumb_path);
                                          break;
                  
                                          // Image/Jpg    
                                          case 'image/jpg';
                                              $img =      getOrientedImage($temp);
                                              $thumb =    imagecreatetruecolor($newwidth, $newheight);
                                                          imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
                                                          imagejpeg($thumb, $thumb_path);
                                          break;
                  
                                          // Image/png    
                                          case 'image/png';
                                              $img =      getOrientedImage($temp);
                                              $thumb =    imagecreatetruecolor($newwidth, $newheight);
                                                          imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
                                                          imagepng($thumb, $thumb_path);
                                          break;
                  
                                          // Image/gif    
                                          case 'image/gif';
                                              $img =      getOrientedImage($temp);
                                              $thumb =    imagecreatetruecolor($newwidth, $newheight);
                                                          imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
                                                          imagegif($thumb, $thumb_path);
                                          break;
                                      }
                  
                  
                                          // Move the original file aswell.
                                          move_uploaded_file($temp, $path);
                  
                  
                                  } else {
                                      ?><div class="add-errors">Your image size is too big!</div><?php
                                  }
                              } else {
                                  ?><div class="add-errors">Your image resolution exceeds the limit!</div><?php
                              }
                  
                          } else {
                              ?><div class="add-errors">Your have uploaded a forbidden extension!</div><?php
                  
                          }
                  
                      }
                  
                  }
                  

                  推荐答案

                  您可能需要查看 exif_read_data() 函数,并查看数组中返回的 ['Orientation'] 值.通常,具有方向传感器的手机或相机将图像存储在一个方向或另一个方向,然后将适当的方向标志添加到图片中的 exif 数据中.然后由图像查看器或图像处理器决定是否在显示或处理图像之前旋转原始图片.

                  You may want to look in to the exif_read_data() function, and look at the ['Orientation'] value that is returned in the array. Typically, a phone or camera that has orientation sensors store the image at one orientation or the other, and then add appropriate orientation flags to the exif data in the picture. It is then up to the image viewer or image processor to determine whether to rotate the raw picture before displaying or processing the image.

                  该页面的评论中有一些很好的例子.

                  There are some great examples in the comments of that page.

                  根据该页面上的示例之一构建的函数:

                  Function built from one of the examples on that page:

                  <?php
                      function getOrientedImage($imagePath){
                          $image = imagecreatefromstring(file_get_contents($imagePath));
                          $exif = exif_read_data($imagePath);
                          if(!empty($exif['Orientation'])) {
                              switch($exif['Orientation']) {
                                  case 8:
                                      $image = imagerotate($image,90,0);
                                      break;
                                  case 3:
                                      $image = imagerotate($image,180,0);
                                      break;
                                  case 6:
                                      $image = imagerotate($image,-90,0);
                                      break;
                              }
                          }
                          return $image;
                      }
                  ?>
                  

                  此外,关于上传时间,如果设备使用手机信号塔传输数据,您的上传速度可能只是下载速度的一小部分.为了比较,大多数社交网络应用程序会在上传之前调整图像大小,而您的网页可能不会.由于手机可以拍摄 8 兆像素或更大的照片,这会增加大量数据.

                  Also, regarding the upload time, if the device is using cell towers to transmit the data, your upload speeds are probably a fraction of your download speeds. For comparisons sake, most social networking apps resize the image before uploading, whereas your web page probably doesn't. Since phones take 8 megapixel or greater photos, that adds up to a lot of data.

                  这篇关于嗯,这是新的.无法从智能手机上传照片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中的按钮文本)

                    <tbody id='xgzA2'></tbody>
                  1. <legend id='xgzA2'><style id='xgzA2'><dir id='xgzA2'><q id='xgzA2'></q></dir></style></legend>
                  2. <i id='xgzA2'><tr id='xgzA2'><dt id='xgzA2'><q id='xgzA2'><span id='xgzA2'><b id='xgzA2'><form id='xgzA2'><ins id='xgzA2'></ins><ul id='xgzA2'></ul><sub id='xgzA2'></sub></form><legend id='xgzA2'></legend><bdo id='xgzA2'><pre id='xgzA2'><center id='xgzA2'></center></pre></bdo></b><th id='xgzA2'></th></span></q></dt></tr></i><div id='xgzA2'><tfoot id='xgzA2'></tfoot><dl id='xgzA2'><fieldset id='xgzA2'></fieldset></dl></div>
                    <tfoot id='xgzA2'></tfoot>

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

                          • <bdo id='xgzA2'></bdo><ul id='xgzA2'></ul>