我的表格有文字投入和档案投入;正对案文领域进行验证。 是否有办法记住用户如果被点击,已经选定哪些档案,但需要回来,因为一个文本领域确实有效?
PHP
原标题:PHP remember file field contents
最佳回答
由于安全原因,你可以“填充”文件上载现场的内容。 而且,这意味着每提交表格时,档案就会重新上载,这并不好。
相反的:
- Create a file upload field with name
file_upload
. - On the server-side, process the upload in any case, even if the rest of the form validation fails.
- If the form validation failed, but the file was uploaded, insert a hidden input into the form with name
file
containing the name of the just uploaded file. - Display a user-visible indication that the file is okay. If it s an image, display a thumbnail version of it. If it s any other file, display its filename and/or icon.
- If the user chooses to upload a different file in the
file_upload
field, process the upload and store the new value infile
.
Pseudocode:
<?php
$file = null;
if (!empty($_POST[ file ])) {
$file = $_POST[ file ];
}
if (!empty($_FILES[ file_upload ])) {
// process upload, save file somewhere
$file = $nameOfSavedFile;
}
// validate form
?>
<input type="file" name="file_upload" />
<input type="hidden" name="file" value="<?php echo $file; ?>" />
<?php
if (!empty($file)) {
echo "File: $file";
}
?>
Important note
该机制可允许任何用户自行申请其他用户的档案,在服务器上填入“<>.file>名称”。 您将确保上载的档案与特定用户明确相关,以避免这一问题。
问题回答
文档输入领域只有读写,才能为它们确定初步价值。
你可以卸下文件,显示档案名称,而不是档案箱。 为记住这些领域,你可以使用“SESSION”变量。
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding