问题
I really despair at this problem. I already found some other threads that consider about this problem, but I don't found a solution for me.
I want to upload a mp3 / mp4 file. But with my current solution only pictures are being uploaded.
This question is only about the core functionality of upload a mp3 / mp4 file - I conscious exclude any security checks or kind of this.
PHP:
if(move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES['file']['name']))
{
echo "Successfully Uploaded Images";
}
else
{
echo "Error while uploading";
}
JS:
file = this.files[i];
if (window.FileReader) {
reader = new FileReader();
reader.onloadend = function(e) {
//showUploadedItem(e.target.result, file.fileName);
};
reader.readAsDataURL(file);
}
if (formdata) {
formdata.append("file", file);
}
if (formdata)
{
$.ajax(
{
url: "upload.php",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function(res)
{
document.getElementById("response").innerHTML = res;
}
});
}
EDIT: I already set the upload_max_filesize to 32 MB.
I got this response from the server:
( ! ) Notice: Undefined index: file in C:\wamp\www\musicplayer_www\public_html\4_upload\upload.php on line 3
Call Stack
# Time Memory Function Location
1 0.0022 134720 {main}( ) ..\upload.php:0
( ! ) Notice: Undefined index: file in C:\wamp\www\musicplayer_www\public_html\4_upload\upload.php on line 3
Call Stack
# Time Memory Function Location
1 0.0022 134720 {main}( ) ..\upload.php:0
EDIT 2: HTML Form:
<div id="main">
<h1>1. upload track to ftp</h1>
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="images" id="images" multiple/>
<button type="submit" id="btn" class="btn btn-default">Upload Files!</button>
</form>
<div id="response"></div>
</form>
</div>
EDIT 3: In reference to this, there some more limits we have to consider:
post_max_size
upload_max_filesize
memory_limit
So the thought of bluesky is in the right direction.
回答1:
I think your mp3,mp4 file too large, you can check Maximum allowed size for uploaded file
in php.ini, default you can upload file with 2Mb, change upload_max_filesize
and restart your server
回答2:
Use the following:
var data = new FormData();
jQuery.each(jQuery('#file')[0].files, function(i, file) {
data.append('file-'+i, file);
});
jQuery.ajax({
url: 'upload.php',
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
alert(data);
}
});
来源:https://stackoverflow.com/questions/34280825/mp3-mp4-php-upload-doesnt-work