Jump to content

Recommended Posts

I'm trying to determine why when I select Upload, on the html page I see a message "My extension is:" only, instead of My extension is: webM" for example.Here's the code, I look forward to any assistance:

<?php
foreach (array('video', 'audio') as $type) {
    if (isset($_FILES["${type}-blob"])) {

        $fileName = $_POST["${type}-filename"];
        $uploadDirectory = 'uploads/' . $fileName;

            // make sure that one can upload only allowed audio/video files
            $allowed = array(
                'webm',
                'wav',
                'mp4',
                'mov'
    );

    $extension = pathinfo($filePath, PATHINFO_EXTENSION);
    die("My extension is: " . $extension);

   if (!$extension || empty($extension) || !in_array($extension, $allowed)) {
        echo 'Invalid file extension: '.$extension;
       return;
 }
        if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $uploadDirectory)) {
            echo (" problem moving uploaded file");
        }
    }
}
?>

 

Thanks for your reply. I don't know the answer. Maybe you can help me, I probably have the code incorrect.

Here's the corresponding javascript that it's working with save1.php (the code I posted above):

<video id="video" autoplay="true" controls muted playsInline></video>

<script>
function supportsRecording(mimeType) {
  if (!window.MediaRecorder) {
    return false;
  }
  if (!MediaRecorder.isTypeSupported) {
    return mimeType.startsWith("audio/mp4") || mimeType.startsWith("video/mp4");
  }
  return MediaRecorder.isTypeSupported(mimeType);
}

var video = document.querySelector("video");
let params = { audio: true, video: { facingMode: { exact: "environment" } } };

//if (navigator.mediaDevices.getUserMedia) {
 // navigator.mediaDevices.getUserMedia({ video: true })
   // .then(function (stream) {
   //   video.srcObject = stream;
   // })
   // .catch(function (err0r) {
  //    console.log("Something went wrong!");
  //  });
//}

let blobs = [];
let stream, mediaRecorder, blob;

async function startRecording() {
  stream = await navigator.mediaDevices.getUserMedia({
    audio: true,
    video: true,
  });

  mediaRecorder = new MediaRecorder(stream);
  mediaRecorder.ondataavailable = (event) => {
    // Let's append blobs for now, we could also upload them to the network.
    if (event.data) {
      blobs.push(event.data);
    }
  };
  mediaRecorder.onstop = doPreview;
  // Let's receive 1 second blobs
  mediaRecorder.start(1000);
}

function endRecording() {
  // Let's stop capture and recording
  mediaRecorder.stop();
  stream.getTracks().forEach((track) => track.stop());
}

function doPreview() {
  if (!blobs.length) {
    return;
  }
  // Let's concatenate blobs to preview the recorded content
  blob = new Blob(blobs, { type: mediaRecorder.mimeType });
  video.src = URL.createObjectURL(
    blob,
  );
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

      function uploadFile() {
	  // create FormData
	  var fileType = 'video'; // or "audio"
	  var fileName = 'ABCXYZ.webm';
	  var formData = new FormData();
	  var request = new XMLHttpRequest;

	  formData.append(fileType + '-filename', fileName);
	  formData.append(fileType + '-blob', blob);
	  request.open("POST", "/save1.php");
	  request.onreadystatechange = function() {
	  if(request.readyState==4) {
	  alert(request.responseText);
	  }
	  }
	  request.send(formData);
}
</script>












 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.