Ich arbeite an einer Website ähnlich wie YouTube, aber für meine Firma. Ich möchte Benutzern ermöglichen, Fotos und Videos selbst hochzuladen (anstatt mich jedes Mal zu fragen).
Ich habe Probleme mit dem Video-Upload-Teil, ich habe die gleiche Technik für den Foto-Upload verwendet und es hat gut funktioniert!
Hier ist mein Code:
$(function() {
$('#my_form').on('submit', function (e) {
e.preventDefault();
var $form = $(this);
var formdata = (window.FormData) ? new FormData($form[0]) : null;
var data = (formdata !== null) ? formdata : $form.serialize();
$.ajax({
url: 'MgtImportVideo.php',
type: 'POST',
contentType: false,
processData: false,
dataType: 'html',
data: data, //data = serialized form
xhr: function(){
//do stuff like showing percentage progress
},
beforeSend : function(){
//do some stuff like incrementing variables
},
success: function (response) {
//do other stuff like diplaying error/sucess messages
}
});
});
I contentType
und processData
auf false gesetzt, weil ich es war, die für den Upload gehört.
Und die eigentliche Videodatei wird wie folgt gespeichert:
$('#my_form').find('input[name="fileVideo[]"]').on('change', function (e) {
var files = $(this)[0].files;
var urivideo=false;
urivideo=window.URL.createObjectURL(files[0]);
//Then do some other stuff (I guess not really important here)
});
Dann in meiner MgtImportVideo.php
Datei, der $ _POST und $ _FILES keine Daten erhalten und als leeren Arrays zeigt.
Kann mir jemand helfen, das herauszufinden?
https://stackoverflow.com/questions/2320069/jquery -ajax-file-upload – tilz0R
Mögliches Duplikat von [jQuery Ajax File Upload] (https://stackoverflow.com/questions/2320069/jquery-ajax-file-upload) –
Bearbeitete Frage, ich benutze Formdata Objekt – NattyRoots