开发者

Get $_POST from type=file

开发者 https://www.devze.com 2023-01-17 08:24 出处:网络
I have form for example: <input type=\"text\" /> <input type=\"file\" /> <input type=\"submit\" />

I have form for example:

<input type="text" />

<input type="file" />

<input type="submit" />

You have to fill the text and the file, 开发者_如何学Goif you dont fill the text for example you have an error message, but I want to preserve what the user filled in the file's input. How to do it with $_POST or somthing else?


I want to preserve what the user filled in the file's input.

Impossible.


NOTE:

$_POST is not the superglobal that will provide information related to 'file' inputs'. Look into you $_FILES superglobal for that kind of information.


You have to specify the "name" attribute of each input to something different:

<input type="text" name="title" />

<input type="file" name="picture"/>

<input type="submit" name="submit_button_1"/>
<input type="submit" name="submit_button_2"/>

Setting the name attribute of the submit input can be useful when you have several of them and you want to know on which one you clicked.


whatever user submits from client-side is not controlled by server-side, but you can:

  • use javascript to "scan" the extension name of file (.php), and prevent other files from not being able to be submitted. However this doesn't stop people renaming other files to .php.

  • the question is what you gonna do with the submitted php file? keep it in database? or execute it? you need to scan its content to make sure it doesn't contain malicious code. I am not very sure how php can do this, though.

0

精彩评论

暂无评论...
验证码 换一张
取 消