title: PHP upload video files to database
body: <p>I am working on a school project that let users upload video files to a server. Server will compress the video using ffmpeg and store the file in upload folder. Other users will be able to stream the uploaded videos. </p>
  
  <p>My question is how do i retrieve the video that ffmpeg generated and store the link in the database?</p>
  
  <p>i am using this code but it only retrieve path of the original video.</p>
  
  <pre><code>$filePath = dirname(__FILE__); 
  </code></pre>
  
  <p>partial code of Upload.php</p>
  
  <pre><code>$target_dir = "upload/"; //where you want to upload the files to
  $target_file = $target_dir.basename($_FILES['file']['name']);
  $fileType = pathinfo($target_file, PATHINFO_EXTENSION);
  $newFileName = $target_dir.sha1(pathinfo(basename($_FILES['file']['name']), PATHINFO_FILENAME)).'-'.time().'.'.$fileType;
  move_uploaded_file($_FILES['file']['tmp_name'], $newFileName);
  $unique_id = rand(1000000,9999999);
  
  shell_exec("C:\\ffmpeg\\bin\\ffmpeg.exe -i ".$newFileName." -vcodec libx264 -crf 20 \"upload\\{$newFileName}\" &gt; logfile.txt 2&gt;&amp;1");
  
  /// save information into database
                  $username = "root";
                  $password = "";
                  $hostname = "localhost"; 
                  $dbname = "test_database";
  
                  //connect to the database
                  $dbc = mysqli_connect($hostname, $username, $password, $dbname) or die ("could not connect to the database");
  
                  //execute the SQL query and return records
                   $result = mysqli_query($dbc, "INSERT INTO `viewvideo` (`vID`, 'video_id`, `video_link`) VALUES ('', '".$unique_id."', '".$newFileName."')");
  
                  if(!$result){echo mysqli_error($dbc); }
  
                  echo $result;
  
              /*  
                  declare in the order variable
                  $result = mysqli_query($dbc, $sql); //order executes
                  if($result){
                      echo("&lt;br&gt;Input data is succeed");
                  } else{
                      echo("&lt;br&gt;Input data is fail");
                  }
              */  
  
                  //close the connection
                  mysqli_close($dbc);
  </code></pre>
  
  <p>output
  <a href="https://i.stack.imgur.com/vyFdG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vyFdG.jpg" alt="enter image description here"></a></p>