Reputation: 458
I am relatively new to php and I am trying to make use of the move_uploaded_file() function.
I firstly send a HTTP POST request from some javascript/jquery to a php file as follows with an audio blob....my php file is hosted on a microsoft azure server...
mediaRecorder.ondataavailable = function(e) {
var fileType = 'audio';
var fileName = 'test.ogg';
var formData = new FormData();
formData.append(fileType + '-filename', fileName);
formData.append(fileType + '-blob', e.data);
// e.data is the audio blob
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
console.log('wooo');
}
};
request.open('POST', myserver/Test.php');
request.send(formData);
}
My PHP code picks up this post request and seems to receive the file with no errors
<?php
print_r($_FILES);
$temp = $_FILES['audio-blob']['tmp_name'];
$name = $_FILES['audio-blob']['name'];
if (isset($_FILES["audio-blob"])) {
$fileName = $_POST["audio-filename"];
$uploadDirectory = 'C:/Users/Liam/PhpRecordings/';
if (move_uploaded_file($temp, $uploadDirectory . $fileName)) {
echo("file moved!!!!");
}
else
{
echo(" problem moving uploaded file");
}
}
?>
<html>
<body>
Test
</body>
</html>
<?
?>
However, when trying to move the file it does not succeed and I get the echo
problem moving uploaded file
The full post response is here
Array ( [audio-blob] => Array ( [name] => blob [type] => audio/ogg [tmp_name] => D:\local\Temp\phpA897.tmp [error] => 0 [size] => 15755 )
) problem moving uploaded file Test
Does anybody know why the file move is not occurring?
Thanks
Upvotes: 1
Views: 351
Reputation: 5534
Is there are enough rights for your code to write to /Users/Liam/PhpRecordings/
?.
Try to run this code and add output into comment for this answer:
echo file_put_contents('/Users/Liam/PhpRecordings/test.txt', 'testing_writing_to_file');
According to the author's further comments there are problems with write privileges to $uploadDirectory
.
There are similar question on SO - Write permissions on mac
Upvotes: 0