Chrisj Posted June 5, 2021 Share Posted June 5, 2021 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"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/312865-help-with-displaying-the-file-extension-message/ Share on other sites More sharing options...
Barand Posted June 5, 2021 Share Posted June 5, 2021 6 minutes ago, Chrisj said: $extension = pathinfo($filePath, PATHINFO_EXTENSION); Where does $filePath get its value from? Quote Link to comment https://forums.phpfreaks.com/topic/312865-help-with-displaying-the-file-extension-message/#findComment-1587037 Share on other sites More sharing options...
Chrisj Posted June 5, 2021 Author Share Posted June 5, 2021 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> Quote Link to comment https://forums.phpfreaks.com/topic/312865-help-with-displaying-the-file-extension-message/#findComment-1587039 Share on other sites More sharing options...
maxxd Posted June 7, 2021 Share Posted June 7, 2021 JavaScript isn't going to set your PHP variable; $filePath is set somewhere earlier in the PHP file. Find that line and post it here. Quote Link to comment https://forums.phpfreaks.com/topic/312865-help-with-displaying-the-file-extension-message/#findComment-1587061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.