Caution: PHP's move_uploaded_file() function is unable to successfully relocate the audio file

I've implemented a straightforward Record Wave script using Recorder.js

Encountering an Issue

  1. Recording works fine
  2. Playback of my recording is successful
  3. Downloading the recorded file from blob works smoothly
  4. The problem arises when trying to upload the record file
  5. Issues with operating system (Windows 10 & appserv)

My upload.php

    <?php
    print $_FILES["audio_data"]["tmp_name"]; //this will display temporary details about the uploaded file
    //checking if the upload folder exists or not
    if(!is_dir("uploads")){
        $res = mkdir("uploads",0777); 
    }

    $size = $_FILES['audio_data']['size']; //size in bytes
    $input = $_FILES['audio_data']['tmp_name']; //temporary name assigned by PHP
    $output = $_FILES['audio_data']['name'].".wav"; //client controls filename, could be improved
    //moving the file from temp location to local folder using given $output name
    move_uploaded_file($input, $output)

    ?>

Snippet from My js file

function createDownloadLink(blob) {

    var url = URL.createObjectURL(blob);
    var au = document.createElement('audio');
    var li = document.createElement('li');
    var link = document.createElement('a');

    //defining filename for .wav file used during upload and download (without extension)
    var filename = new Date().toISOString();

    //controlling audio element
    au.controls = true;
    au.src = url;

    //link to save file to disk
    link.href = url;
    link.download = filename+".wav"; 
    link.innerHTML = "Save to disk";

    //appending controls to the list item
    li.appendChild(au);

    //adding filename to the list item
    li.appendChild(document.createTextNode(filename+".wav "))

    //including save to disk link into the list item
    li.appendChild(link);

    //link for uploading
    var upload = document.createElement('a');
    upload.href="#";
    upload.innerHTML = "Upload";
    upload.addEventListener("click", function(event){
          var xhr=new XMLHttpRequest();
          xhr.onload=function(e) {
              if(this.readyState === 4) {
                  console.log("Server returned: ",e.target.responseText);
              }
          };
          var fd=new FormData();
          fd.append("audio_data",blob, filename);
          xhr.open("POST","upload.php",true);
          xhr.send(fd);
    })
    li.appendChild(document.createTextNode (" "))//add a space between elements
    li.appendChild(upload)//add the upload link

    //append the list item to the ordered list
    recordingsList.appendChild(li);
}

Error encountered on clicking upload button

<b>Warning</b>:  move_uploaded_file(2019-12-05T17:30:46.190Z.wav): failed to open stream: Invalid argument in <b>F:\AppServ\www\audio\upload.php</b> on line <b>12</b><br />
<br />
<b>Warning</b>:  move_uploaded_file(): Unable to move 'C:\Windows\Temp\php891B.tmp' to '2019-12-05T17:30:46.190Z.wav' in <b>F:\AppServ\www\audio\upload.php</b> on line <b>12</b><br />

Answer №1

An error is being caused because you are setting the output directory as the filename.

Since your upload directory is set as 'uploads'.

To resolve this issue, make sure to adjust the code like this:

$output ="uploads/".$_FILES['audio_data']['name'].".wav";

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When IntelliJ starts Spring boot, resources folder assets are not served

I'm following a tutorial similar to this one. The setup involves a pom file that manages two modules, the frontend module and the backend module. Tools being used: IDE: Intellij, spring-boot, Vue.js I initialized the frontent module using vue init w ...

Displaying an image prior to the component rendering in Vue.js

In my Vue application, I have a list of events that are displayed individually. When I visit the page of a selected event, an error message appears in my console: GET http://localhost:1337/undefined 404 (Not Found). However, the image still loads correctly ...

What causes the variance in behavior between the Angular-formly directive and type?

I am facing an issue with two input fields that are both generated using the same template. I have set the required attribute to true for both of them by using the following code snippet: ... templateOptions: { ... required: true } One input fiel ...

Struggling to get JQuery timing events to function properly?

Encountering timing issues with the events in my self-made simon memory game. Experimented with setTimeout but struggling to figure out which events to time and the appropriate duration for them to be distinguishable. $('#play').click(function( ...

Using MongoDB and NodeJS to retrieve data from a promise

When I make a request to the database using promises, my goal is to extract the values of "latitude" and "longitude" for all documents and store them in an array. This is how I am currently approaching it: const promises = [ dbo.collection("users").f ...

The onchange event does not seem to be functioning as expected in a dropdown menu that was dynamically added from a separate

Is there a way to display a list of tables from a database in a dropdown menu and allow users to select a table name? When a user selects a table name, I would like to show all the data associated with that table. The HTML file structure is as follows: & ...

What is the best way to change a NSString from JSON into an NSDictionary?

FINAL EDIT WITH THE SOLUTION: A resolution to the issue is presented below: -(void) attackLawyers { lawyers = [[[NSArray alloc] init] autorelease]; NSLog(@"%@", userReceived); NSString *myRequestString = [NSString stringWithFormat:@"user=%@", userRece ...

What purpose does the "io" cookie serve in Socket.IO?

Can someone explain the purpose of Socket.IO using the io cookie as a session cookie? I understand that it can be disabled, but I couldn't find any information on it in the documentation. Why is it turned on by default and what consequences would ther ...

How Python Flask sends a string as &#34 to an HTML page

I am working on a Flask app and I need to send simple JSON data from the app.py file to an HTML page. Here is the relevant code in my app.py: jsonArr = [{"type": "circle", "label": "New York"}, {"type": "circle", "label": "New York"}] return ...

Testing in Jasmine: Verifying if ngModelChange triggers the function or not

While running unit tests for my Angular app, I encountered an issue with spying on a function that is called upon ngModelChange. I am testing the logic inside this function but my test fails to spy on whether it has been called or not! component.spec.js ...

Create an .htaccess RewriteRule that can generate a URL with two parameters in any order

I am facing an issue with the URL structure containing 2 parameters https://mywebsite.com/folder/subfolder/page.php?id=999&title=this-is-a-test I require a rule to transform the above URL into the following format: https://mywebsite.com/page/this-is ...

Arrange products in WooCommerce based on stock availability and display a specific image for each product

I came across a code snippet to organize my products in the functions.php file based on their stock status. However, I have over 1000 products and some of them have a generic image named "no2.png" because they do not have a specific product image. I want t ...

What is the reason behind having several node modules directories within every project?

I'm just starting out with JS development and I have a question about the size of node modules. It seems that when many projects accumulate, we end up having to delete the node_modules folder because it takes up so much space. So, why isn't there ...

Material-UI now offers the ability to customize the shadows array within createMuiTheme to support up to 25 different elevations

Currently working on removing shadows in the Material-UI theme. Came across this useful solution that fixed the issue. However, encountered an error related to this topic. const theme = createMuiTheme({ palette: { primary: { light: red[300], ...

The lifespan of a PHP object

As my files became longer than 100 lines, I started considering breaking them into smaller functional parts. However, when I attempted to do so, I encountered a problem as shown in the simplified code below. I understand that HTTP is stateless and variable ...

Problem encountered while trying to publish a post using Iron Router

I'm encountering some difficulties when trying to create a route that allows me to respond to comments (.../comments/:_id/reply) and publish the related post. Below is the code snippet: Publications Meteor.publish('commentUser', function(c ...

Create interactive highcharts graphs using data from a CSV file generated through PHP

I'm having trouble working with Highcharts and csv data. Take a look at this example: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/line-ajax/ $.getJSON('http://www.highcharts.com/ ...

What is the best way to simulate our services for controller testing?

Currently delving into angular js and experimenting with testing a controller. Here is the service I am using: angular.module('test'){ service.getAllServices = function() { var fullPath = url var deferre ...

The Infinite Scroll feature is malfunctioning when the $(window).scrollTop() is greater than or equal to $(document).height() - $(window).height() - 10

JavaScript: $.ajax({ type: 'POST', url: 'getcontent.php', data: 'lastid=' + 0, dataType: "html", success: function (data) { console.log(data); $("#content").appe ...

Is there a way to receive live updates for records in real-time using push notifications?

I am in the process of developing a Ruby on Rails ecommerce platform that enables potential customers to place orders while allowing the store owner to receive them instantaneously. Once an order is finalized, it will be saved into the database (currently ...