php - 视频上传有问题帖子变量没有到达那里

标签 php qt video ffmpeg

请看下面的代码

   <?php
 session_start();
 include "conn.php";
 $sid = $_SESSION['id'];
  $ipIP=$_SERVER['REMOTE_ADDR'];
 $uploaddir = "mem/$sid/video/";

 //Check the file is of correct format.  
  function checkfile($input){
  $ext = array('mpg', 'wma', 'mov', 'flv', 'mp4', 'avi', 'qt', 'wmv', 'rm',    'mkv', 'MP4');
$extfile = substr($input['name'],-4);
$extfile = explode('.',$extfile);
   $good = array();
   @$extfile = $extfile[1];
      if(in_array($extfile, $ext)){
     $good['safe'] = true;
     $good['ext'] = $extfile;
     }else{
      $good['safe'] = false;
  }
  return $good;
}
if(!isset($_POST['profileimage99']) || $_FILES["profileimage99"]["size"] ==''){
echo 'No file added';die;
 }
  // if the form was submitted process request if there is a file for uploading
  if(@$_FILES["profileimage99"]["size"] < 102400000000){
   //$live_dir is for videos after converted to flv
    $live_dir = "mem/$sid/video/";
  //$live_img is for the first frame thumbs.
    $live_img = "mem/$sid/img/";        
    $seed = rand(11111111111193,9999999999999929) * rand(3,9);
    $getEXT=substr(@$_FILES['profileimage99']['name'],-5);
    $upload = $seed.$getEXT;
    $uploadfile = $uploaddir .$upload;        

    $safe_file = checkfile(@$_FILES['profileimage99']);
    if($safe_file['safe'] == 1){
                if (move_uploaded_file(@$_FILES['profileimage99']['tmp_name'], $uploadfile)) {
                echo "Video uploaded.";

                $base = basename($uploadfile, $safe_file['ext']);
                $new_file = $base.'flv';
                $new_image = $base.'jpg';
                $new_image_path = $live_img.$new_image;
                $new_flv = $live_dir.$new_file;

        require 'vendor/autoload.php';
        //ececute ffmpeg generate flv
        exec('ffmpeg -i '.$uploadfile.' -f flv -s 640x360 '.$new_flv.'');
        //execute ffmpeg and create thumb
        exec('ffmpeg  -i '.$uploadfile.' -f mjpeg -vframes 17 -s 426x240 -an '.$new_image_path.'');
        echo 'Thank You For Your Video!<br/>';

    //create query to store video
    if(isset($_POST['title'])){$titlename=$_POST['title'];}else{$titlename='';}
    if(isset($_POST['desc'])){$desc=$_POST['desc'];}else{$desc='';}
    if(isset($_POST['catag'])){$catag=$_POST['catag'];}else{$catag='';}
    if(isset($_POST['channel'])){$channel=$_POST['channel'];}else{$channel='';}
    $dbentry_o=mysqli_query($conn,"insert into vids (uid,chid,ctid,vname,vdisc,duration,time,ip,src) values ('$sid','$channel','$catag','$titlename','$desc','00','00','$ipIP','$new_file')");
    echo "donr90909090";die;
         } else {
                echo "Possible file upload attack!\n";
                print_r($_FILES);
         }

        }else{

         echo 'Invalid File Type Please Try Again. You file must be of type 
         .mpg, .wma, .mov, .flv, .mp4, .avi, .qt, .wmv, .rm'.$_FILES['profileimage99']['name'];

    }
 }else{
 echo 'Please choose a video';die;
  }
  ?>

我正在提交此表格
 <form style="margin:0px;display:none;" action="videoupload.php" method="post" id="thef_op90op">
            <input type="file" name="profileimage99" style="display:none;" onchange="showandfade();" id="file09_09o9_9908ij">
            </form>

到上面的页面
当我提交表单时,我收到错误没有添加文件,就像帖子变量没有在页面上到达一样,当我删除验证时
  if(!isset($_POST['profileimage99']) || $_FILES["profileimage99"]["size"] ==''){
echo 'No file added';die;
 }

我可以上传一些通常小于 2 mb 的文件,但对于较大的文件,我得到 profileimage99 的未定义索引错误。

我从 php.ini 文件中增加了 upload_max_size

请注意表单是通过 ajax 调用提交的

最佳答案

您需要设置 enctype 属性。
更多信息请访问 HTML enctype Attribute

 <form enctype="multipart/form-data" style="margin:0px;display:none;" action="videoupload.php" method="post" id="thef_op90op">
     <input type="file" name="profileimage99" style="display:none;" onchange="showandfade();" id="file09_09o9_9908ij">
 </form>

如果您发送 multipart/form-data来自 profileimage99 的数据将在 $_FILES多变的。因此,您应该将查询更改为以下内容:
if(!isset($_FILES['profileimage99']) || $_FILES["profileimage99"]["size"] <= 0){
    echo 'No file added';
 }

关于php - 视频上传有问题帖子变量没有到达那里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31716053/

相关文章:

php - 如何在电子邮件中嵌入图像

c++ - Qt 将 QImage 保存到相对位置

qt - Qt lib捕获用户的声卡输出

c++ - Qt 获取样式表边框颜色

html - 视频播放器 : HTML5 vs Youtube API

PHP XPath 选择最后一个匹配元素

php - 无论年份如何过生日

php - 下载 php 脚本图像

php - 录制视频并将其保存到php服务器

flash - 我的 mediaelement.js 播放器在暂停/停止时如何停止下载?