It uses the symfony framework and jquery to upload images, but the background cannot accept data. Code and error message: {code ...} {code ...} the background code is as follows: {code ...} the error message is: Notice: Undefinedindex: files []. What is the problem? Thank you. It uses the symfony framework and jquery to upload images, but the background cannot accept data. The code and error message are as follows:
$(document).ready(function(){ $("#fileupload").fileupload({ dataType: 'json', done: function (e, data) { $.each(data.result.files, function (index, file) { $('').text(file.name).appendTo(document.body); }); }, progressall: function (e, data) { var progress = parseInt(data.loaded / data.total * 100, 10); $('#progress .bar').css( 'width', progress + '%' ); }, done: function (e, data) { $.each(data.result, function (index, file) { $('').text(file.name + ' uploaded').appendTo($("body")); }); } }); });
The background code is as follows:
$imgPurpose = trim(stripslashes($_POST["files[]"]));
The error message is as follows:
Notice: Undefined index: files []
What is going on? Thank you.
Reply content:
It uses the symfony framework and jquery to upload images, but the background cannot accept data. The code and error message are as follows:
$(document).ready(function(){ $("#fileupload").fileupload({ dataType: 'json', done: function (e, data) { $.each(data.result.files, function (index, file) { $('').text(file.name).appendTo(document.body); }); }, progressall: function (e, data) { var progress = parseInt(data.loaded / data.total * 100, 10); $('#progress .bar').css( 'width', progress + '%' ); }, done: function (e, data) { $.each(data.result, function (index, file) { $('').text(file.name + ' uploaded').appendTo($("body")); }); } }); });
The background code is as follows:
$imgPurpose = trim(stripslashes($_POST["files[]"]));
The error message is as follows:
Notice: Undefined index: files []
What is going on? Thank you.
A simple answer to your question is as follows:
Premise: You have never used thisjQueryPlug-ins, so only considerBackground code
First, in the Form Control'snameWhen the attribute value is an array (add[]), When using PHP to obtain the content submitted by the control, it should be omitted[]So your code should be as follows:
$_POST["files"]);
2. Use$_POSTGlobal variable accessfilesThe result is a PHP array. Therefore, the string function cannot be used directly for processing (the string function is not discussed here for the time being)
Third, you are usingSymfonyFramework, should not be accessed directly$_POSTAnd other global variables!SymfonyOfHttpFoundationThe component has abstracted these global variablesOOPInterface, you should useSymfonyProvided interface. As shown below: (assume that your Controller method is as follows)
//...use Symfony\Component\HttpFoundation\Request;// ...public function uploadAction(Request $request){ $imgPurpose = $request->get('files');}// ...
Finally,SymfonyOfHttpFoundationThe component has powerful functions. The following are links to its official documentation.SymfonyThe framework is very helpful.
Symfony and Http Basics
HttpFoundation component documentation
Note: andSymfonyFor related questions, addSymfonyLabelSymfonyThe answer authors are more interested in the question. (A prompt is displayed when you enter the content, as shown in figure)