Friends, the situation is this. There is a script that wants to upload a file to the server on the command of the form. As described in the documentation (which is very poor), the POST download method is understandable. Unfortunately, I don’t understand how I can get it on my side, since I don’t see it in the documentation, and I can’t look into the middle either, what is the name of the file that will be downloaded. Is there any way to bypass this and load all the files that will be received by such a command?

http://domain.com/index.php?r=Terminals/Upload&id=1111 

Processing those files that have a name I do like this (uploading an avatar for example):

 if(is_uploaded_file($_FILES["avatar"]["tmp_name"])) { $filename = $_FILES['avatar']['name']; mt_srand((double)microtime()*1000000); $img = ""; for ($i = 0; $i < 8; $i++) { $img .= chr(rand(97, 122)); } $newfilename = 'agent-'.$img; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); move_uploaded_file($_FILES["avatar"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']."/images/users/".$newfilename.$ext); } 
  • not very clear question. in the boot handler, do print_r ($ _ FILES) and see the result. - Michael Livach
  • The question is, the script sends a file through its form. I do not know what is written in his name in his form. Therefore, $ _FILES ["file name don’t know what to write"] - WhoIsDT
  • Maybe you can just help me in this way, I need to know $ _FILES ["this is the name"] ["tmp_name"] of any of the files that comes to the server - WhoIsDT

1 answer 1

without seeing the code that sends, it is difficult to advise something. If the name of the input for the file (in the example is "avatar") is arbitrary each time, then you can use

 foreach($_FILES as $k=>$v){ // тут что-то полезное } 

or

 $inputNames = array_keys(($_FILES); 

or (for one file)

 reset($_FILES); $inputName = key($_FILES); 
  • Fine! Yes you are right. I really can not see the code that sends the script. Therefore, to such methods and need to resort. Thank you very much the third option just fits. This is just what I need - WhoIsDT
  • So, in the piggy bank, as a replacement for the latest current($_FILES) . - E_p
  • if you have already iterated over $ _FILES somewhere before the code, then current ($ _ FILES) returns false. If you always take the first element, it is better to reset ($ _ FILES) - it not only rewinds the internal pointer to the beginning, but also returns the first element (if the array is not empty) - Michael Livach