Populate FILE field with default text

有些话、适合烂在心里 提交于 2019-12-31 02:54:07

问题


I'm trying to reutilize code that generates FILE fields for use when something is to be added to the database, and grayed out (and disabled) with data already in the database when the item in question is being edited or viewed in detail. However, I can't seem to get the text to fill the field. I'm using this:

echo '<input type="file" name="small[]" value="' . $value_from_database . '" DISABLED><br>';

Am I missing anything? If not, are there any decent workarounds?


回答1:


This is not possible due to security restrictions. Imagine that this was possible, then one would be able to develop such a webpage:

<!doctype html>
<html lang="en">
    <head><title>Gimme yer passwords.txt!</title></head>
    <body onload="document.upload.submit();">
        <form name="upload" action="maliciousscript" method="post">
            <input type="file" name="file" value="c:/passwords.txt">
            <input type="submit">
        </form>
    </body>
</html>

I would instead just show it in a simple <input type="text" disabled> field.




回答2:


I believe you can't change that. Instead, use a hidden input to pass the default value:

<input type="hidden" name="file_default" value="..." />



来源:https://stackoverflow.com/questions/2862357/populate-file-field-with-default-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!