muaz-khan / RecordRTC

RecordRTC is WebRTC JavaScript library for audio/video as well as screen activity recording. It supports Chrome, Firefox, Opera, Android, and Microsoft Edge. Platforms: Linux, Mac and Windows.
https://www.webrtc-experiment.com/RecordRTC/
MIT License
6.49k stars 1.75k forks source link

How does Muaz's server handle PHP? #727

Open rayj00 opened 3 years ago

rayj00 commented 3 years ago

I am trying to upload a blob(webm) file to the server but no matter what I use from Muaz's code examples, it won't work.

I am confused on how the server is supposed to accept PHP?

If you are using PHP with Muaz's server code please let me know how you do it.

Thanks,

Ray

zahidgani commented 3 years ago

Hi Here is the full code working fine for me to record video and upload it to your folder

index.php <!DOCTYPE html>

RecordRTC Upload to PHP

save.php

*header("Access-Control-Allow-Origin: "); error_reporting(E_ALL); ini_set('display_errors', 1);

set_error_handler("someFunction");

function someFunction($errno, $errstr) { echo '

Upload failed.


'; echo '

'.$errstr.'

'; }

function selfInvoker() { if (!isset($_POST['audio-filename']) && !isset($_POST['video-filename'])) { echo 'Empty file name.'; return; }

  // do NOT allow empty file names
  if (empty($_POST['audio-filename']) && empty($_POST['video-filename'])) {
      echo 'Empty file name.';
      return;
  }

  // do NOT allow third party audio uploads
  if (false && isset($_POST['audio-filename']) && strrpos($_POST['audio-filename'], "RecordRTC-") !== 0) {
      echo 'File name must start with "RecordRTC-"';
      return;
  }

  // do NOT allow third party video uploads
  if (false && isset($_POST['video-filename']) && strrpos($_POST['video-filename'], "RecordRTC-") !== 0) {
      echo 'File name must start with "RecordRTC-"';
      return;
  }

  $fileName = '';
  $tempName = '';
  $file_idx = '';

  if (!empty($_FILES['audio-blob'])) {
      $file_idx = 'audio-blob';
      $fileName = $_POST['audio-filename'];
      $tempName = $_FILES[$file_idx]['tmp_name'];
  } else {
      $file_idx = 'video-blob';
      $fileName = $_POST['video-filename'];
      $tempName = $_FILES[$file_idx]['tmp_name'];
  }

  if (empty($fileName) || empty($tempName)) {
      if(empty($tempName)) {
          echo 'Invalid temp_name: '.$tempName;
          return;
      }

      echo 'Invalid file name: '.$fileName;
      return;
  }

  /*
  $upload_max_filesize = return_bytes(ini_get('upload_max_filesize'));
  if ($_FILES[$file_idx]['size'] > $upload_max_filesize) {
     echo 'upload_max_filesize exceeded.';
     return;
  }
  $post_max_size = return_bytes(ini_get('post_max_size'));
  if ($_FILES[$file_idx]['size'] > $post_max_size) {
     echo 'post_max_size exceeded.';
     return;
  }
  */

  $filePath = 'uploads/' . $fileName;

  // make sure that one can upload only allowed audio/video files
  $allowed = array(
      'webm',
      'wav',
      'mp4',
      'mkv',
      'mp3',
      'ogg'
  );
  $extension = pathinfo($filePath, PATHINFO_EXTENSION);
  if (!$extension || empty($extension) || !in_array($extension, $allowed)) {
      echo 'Invalid file extension: '.$extension;
      return;
  }

  if (!move_uploaded_file($tempName, $filePath)) {
      if(!empty($_FILES["file"]["error"])) {
          $listOfErrors = array(
              '1' => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
              '2' => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
              '3' => 'The uploaded file was only partially uploaded.',
              '4' => 'No file was uploaded.',
              '6' => 'Missing a temporary folder. Introduced in PHP 5.0.3.',
              '7' => 'Failed to write file to disk. Introduced in PHP 5.1.0.',
              '8' => 'A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.'
          );
          $error = $_FILES["file"]["error"];

          if(!empty($listOfErrors[$error])) {
              echo $listOfErrors[$error];
          }
          else {
              echo 'Not uploaded because of error #'.$_FILES["file"]["error"];
          }
      }
      else {
          echo 'Problem saving file: '.$tempName;
      }
      return;
  }

  echo 'success';

} selfInvoker();**

rayj00 commented 3 years ago

Thanks Zahid. The problem is I am using RTCMulticonnections with Scalable Broadcasting. So RTCMulticonnections does the getUserMedia. I can create the blob (webm) using RecordRTC. I have a start recording button and stop recording. I just need to save the blob to server and then convert it to mp4 (which I will use ffmpeg.). I am not sure your code will work?

rayj00 commented 3 years ago

I am getting a little further in my issue. When I enter your uploadtoPHP, I am getting this in the console:

12:31:51.435 response - PHP upload Progress 66% bcast.streamingworld.us:329:13 12:31:51.486 response - PHP upload Progress 68% bcast.streamingworld.us:329:13 12:31:51.537 response - PHP upload Progress 66% bcast.streamingworld.us:329:13 12:31:51.589 response - PHP upload Progress 70% bcast.streamingworld.us:329:13 12:31:51.641 response - PHP upload Progress 66% bcast.streamingworld.us:329:13 12:31:51.752 response - PHP upload Progress 74% bcast.streamingworld.us:329:13 12:31:51.803 response - PHP upload Progress 68% bcast.streamingworld.us:329:13 12:31:51.854 response - PHP upload Progress 66% bcast.streamingworld.us:329:13 12:31:51.978 response - PHP upload Progress 74% bcast.streamingworld.us:329:13 12:31:52.111 response - PHP upload Progress 66% bcast.streamingworld.us:329:13 12:31:52.162 response - PHP upload Progress 70% bcast.streamingworld.us:329:13 12:31:52.192 response - PHP upload failed.

Any ideas why?

zahidgani commented 3 years ago

Here is the full code you can check and work it fine.

On Tue, Feb 23, 2021 at 11:26 PM rayj00 notifications@github.com wrote:

I am getting a little further in my issue. When I enter your uploadtoPHP, I am getting this in the console:

12:31:51.435 response - PHP upload Progress 66% bcast.streamingworld.us:329 :13 12:31:51.486 response - PHP upload Progress 68% bcast.streamingworld.us:329 :13 12:31:51.537 response - PHP upload Progress 66% bcast.streamingworld.us:329 :13 12:31:51.589 response - PHP upload Progress 70% bcast.streamingworld.us:329 :13 12:31:51.641 response - PHP upload Progress 66% bcast.streamingworld.us:329 :13 12:31:51.752 response - PHP upload Progress 74% bcast.streamingworld.us:329 :13 12:31:51.803 response - PHP upload Progress 68% bcast.streamingworld.us:329 :13 12:31:51.854 response - PHP upload Progress 66% bcast.streamingworld.us:329 :13 12:31:51.978 response - PHP upload Progress 74% bcast.streamingworld.us:329 :13 12:31:52.111 response - PHP upload Progress 66% bcast.streamingworld.us:329 :13 12:31:52.162 response - PHP upload Progress 70% bcast.streamingworld.us:329 :13 12:31:52.192 response - PHP upload failed.

Any ideas why?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/muaz-khan/RecordRTC/issues/727#issuecomment-784389077, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQEYI2TS7BGK6D3NFKAY6LTAPT43ANCNFSM4XRCQHOA .

rayj00 commented 3 years ago

Where is fileDownloadURL initialized?

zahidgani commented 3 years ago

Here is only the code we have applied Start Record Stop Record When you stop record Upload button will be on When you click on upload button it save video in your local computer folder and there will be you can sent download path

zahidgani commented 3 years ago

You may download full code here: http://webdhamaal.com/recordrst.zip

rayj00 commented 3 years ago

I already can save it locally. That is not what I need, I need to send it from client to server!

zahidgani commented 3 years ago

that the save code also work on server side i have already applied it on server side what is the actual issue you are facing?

On Fri, Feb 26, 2021 at 2:14 AM rayj00 notifications@github.com wrote:

I already can save it locally. That is not what I need, I need to send it from client to server!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/muaz-khan/RecordRTC/issues/727#issuecomment-786190995, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQEYI5PYKQHWFLFSLBDKWLTA2ZBPANCNFSM4XRCQHOA .

rayj00 commented 3 years ago

See my comment above from Feb 23.

rayj00 commented 3 years ago

It's Apache2 that handles the PHP and not the node server!

rayj00 commented 3 years ago

I had to reload PHP. Everything working now!! Yahoo!!!

zahidgani commented 3 years ago

Glad to hear it!

On Sat, Mar 6, 2021 at 6:58 PM rayj00 notifications@github.com wrote:

I had to reload PHP. Everything working now!! Yahoo!!!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/muaz-khan/RecordRTC/issues/727#issuecomment-791940377, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQEYI5RMVG6ZCFSJKNR4STTCIUYHANCNFSM4XRCQHOA .

jimztercrack commented 3 years ago

Please, If you want to choose a particular camera, How I can do it?,

rayj00 commented 3 years ago

Please, If you want to choose a particular camera, How I can do it?,

I am having the same issue....changing camera (front/back) for mobile broadcast. I really need this!