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 thisjQuery
Plug-ins, so only considerBackground code
First, in the Form Control'sname
When 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$_POST
Global variable accessfiles
The 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 usingSymfony
Framework, should not be accessed directly$_POST
And other global variables!Symfony
OfHttpFoundation
The component has abstracted these global variablesOOP
Interface, you should useSymfony
Provided 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,Symfony
OfHttpFoundation
The component has powerful functions. The following are links to its official documentation.Symfony
The framework is very helpful.
Symfony and Http Basics
HttpFoundation component documentation
Note: andSymfony
For related questions, addSymfony
LabelSymfony
The answer authors are more interested in the question. (A prompt is displayed when you enter the content, as shown in figure)