【问题标题】:Can't upload video to folder using PHP? [duplicate]无法使用 PHP 将视频上传到文件夹? [复制]
【发布时间】:2019-12-27 01:38:05
【问题描述】:

我正在制作一个上传系统,用户可以在其中上传图片和视频,但上传系统出现问题。主要是上传视频。图片很好,可以上传,但是当我尝试上传视频时问题就开始了。当我尝试上传视频时它没有显示任何错误所以我什至不知道问题是什么。这是目前我的 PHP 代码:

<?php 

    if(isset($_POST['btn-add']))
    {
        $name=$_POST['user_name'];
        $images=$_FILES['profile']['name'];
        $path = "uploads/";
        $rand=rand(1000, 1000000);
        $filename = "$rand.jpg";
        $filepath = "$path$filename";

                function correctImageOrientation($filename) {
  if (function_exists('exif_read_data')) {
    $exif = exif_read_data($filename);
    if($exif && isset($exif['Orientation'])) {
      $orientation = $exif['Orientation'];
      if($orientation != 1){
        $img = imagecreatefromjpeg($filename);
        $deg = 0;
        switch ($orientation) {
          case 3:
            $deg = 180;
            break;
          case 6:
            $deg = 270;
            break;
          case 8:
            $deg = 90;
            break;
        }
        if ($deg) {
          $img = imagerotate($img, $deg, 0);        
        }
        // then rewrite the rotated image back to the disk as $filename 
        imagejpeg($img, $filename, 95);
      } // if there is some rotation necessary
    } // if have the exif orientation info
  } // if function exists      
}

        $imgExt=strtolower(pathinfo($images,PATHINFO_EXTENSION));
         move_uploaded_file($_FILES["profile"]["tmp_name"], $filepath); 


        if($imgExt == "jpg" || $imgExt == "jpeg" || $imgExt == "png" || $imgExt == "gif"){

         correctImageOrientation($filepath);


        if ($imgExt == "jpeg" || $imgExt == "jpg") {
            $im = imagecreatefromjpeg($filepath);
        }else if($imgExt == "png"){
            $im = imagecreatefrompng($filepath);
        }else if($imgExt == "gif"){
            $im = imagecreatefromgif($filepath);
        }
        $size = getimagesize($filepath);

             $width = imagesx($im);
             $height = imagesy($im);
             $newwidth= 300;
             $newheight= 300;


                if(($width/$newwidth) < ($height/$newheight)){
                    $y = 0;
                    $x = $width - (($height * $newwidth) / $newheight);
                }else{
                    $x = 0;
                    $y = $height - (($width * $newheight) / $newwidth);
                }

             $virtual_image = imagecreatetruecolor(301, 301);
             imagealphablending($virtual_image, true);
             imagesavealpha($virtual_image, true);



             imagecopyresampled($virtual_image,$im,0,0, $x/2, $y/2, $newwidth, $newheight, $width-$x, $height-$y); 
             $bgcolor = imagecolorallocatealpha($virtual_image,255,255,255,127);

             imagefill($virtual_image,0,0,$bgcolor);

             imagecolortransparent($virtual_image, $bgcolor);


             imagejpeg($virtual_image,$filepath,100);

             }else if ($imgExt == "mp4"){   

             }else echo "Invalid file";



            $stmt=$db_conn->prepare('INSERT INTO tbl_user(username, picprofile) VALUES (:uname, :upic)');
            $stmt->bindParam(':uname', $name);
            $stmt->bindParam(':upic', $filename);
            if($stmt->execute())
        {
            ?>
            <script>

            </script>
            <?php

        }else

        {
            ?>
            <script>

            </script>
        <?php
        }

    }
?>

【问题讨论】:

    标签: php video xampp mp4


    【解决方案1】:

    对不起,我无法发表评论,所以我只是作为答案发布,但你没有指定如果文件扩展名是 Mp4 代码应该做什么

       }else if ($imgExt == "mp4"){  
    //here should contain your codes and commands if the file is mp4 
     }
    

    因此php不处理文件也没有错误,请检查具体的上传文件夹和临时文件夹

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-06
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多