-2

Hello I need a little help, how I get this same name what I have in html in to php ?

In html I have :

<input type="file" name="data[UploadFile][file_upload][]" id="uploadFilefiles">

and in php :

$this->request->data['UploadFile']['name'] = $this->request->data['UploadFile']['file_upload']['name'];

How can I use these [] what I have in html in php ?

7
  • What system is it? What is in "$this" object, I mean what is the class which contains this PHP code? And why You use so these brackets in HTML? Doesn't seems normal :P Commented Jan 9, 2015 at 12:40
  • I use CakePHP framework Commented Jan 9, 2015 at 12:41
  • OK. Is this Your code or part of this framework? Both HTML and PHP. Commented Jan 9, 2015 at 12:47
  • what u mean ? Yes I use these codes by using CakePHP Commented Jan 9, 2015 at 12:48
  • this is you manual html code[] you can't write this you must write into $this->Form->input('UploadFile.file_upload.'); Commented Jan 9, 2015 at 13:38

1 Answer 1

0

in HTML you have

<input type="file" name="data[UploadFile][file_upload][]" id="uploadFilefiles">

So you get (if you use the method "post" in your form) an array in PHP:

print_r($_POST['data']['UploadFile']['file_upload']);

look here and scroll down:

http://php.net/manual/en/faq.html.php

Sign up to request clarification or add additional context in comments.

7 Comments

Its not helping me, I need something like this : $this->request->data['UploadFile']['file_upload']['[]']['name']; , but its not working , its wrong way to do this.
try to print_r($this->request->data) ... what do you get back? this construct from you will not work, because [] is a new array in php. you can show the data with print_r($this->request->data['UploadFile']['file_upload']);
Ofc I get nothing if I print it, but If I remove in html [] and doing this : print_r($this->request->data['UploadFile']['file_upload']); die; Then I got what I need. BUT I uploading multiple files, and thanks to this I need these []
look if this can help you: stackoverflow.com/questions/4062217/…
the problem with this [] in html is: in php they are after $data['UploadFile']['file_upload'][x]['name'] (just replace x with the index of your file, zero based)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.