简体   繁体   English

如何更改为文件输入形式或“ input type ='file'”显示的文本

[英]how do I change the text that is displayed for file input form, or “ input type='file' ”

Is there an attribute for this? 有这个属性吗? Because if there is I can't find it. 因为如果找不到我。

What I want to do is just echo out the file name that was selected by the user after the form is submitted. 我想做的就是在提交表单后回显用户选择的文件名。 To be clear, it already shows the file name, but problem is that the form could get submitted in the wrong state, in which case, the yellow text goes back to "No file chosen." 为了清楚起见,它已经显示了文件名,但是问题在于表单可能以错误的状态提交,在这种情况下,黄色文本返回到“未选择文件”。 I just need the file name to persist after submitting the form. 提交表单后,我只需要保留文件名即可。

I have a form... 我有一个表格...

 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">



                    <?php
//upload files here. 

                    $fcount = 0;
                    foreach ($layouts[$my_layout] as $key => $value) {
                        //create the form
                        echo 'choose an image with an aspect ratio of ' . $value;
                        ?>
                    <input type="file" name="filesToUpload[]" >
</form>

on the page, I want to change the yellow text to the file name, when such a file is chosen, once the form is submitted. 在页面上,一旦提交表单,我想将黄色文本更改为文件名。

在此处输入图片说明

While your explicit question is asking how to change the text, the implied question is that you want to set the value of the input so the same file will be uploaded again. 当您的显式问题询问如何更改文本时,隐含的问题是您要设置输入的值,以便将同一文件再次上载。

You can't do that. 你不能那样做。 That would require allowing the page author to determine what file gets uploaded from the user's computer. 那将需要允许页面作者确定从用户计算机上载了什么文件。 This would be a serious security risk. 这将是严重的安全风险。

What you can do is store the uploaded file on the server (eg in a temp directory that has old files deleted on a regular basis, eg with cron), and put a reference to it in the new form. 您可以做的是将上载的文件存储在服务器上(例如,在具有定期删除旧文件的temp目录中,例如使用cron),然后以新格式对其进行引用。

 <label> <input type="checkbox" name="already_uploaded_file" value="my_file_identifier" checked> Use foo.jpeg </label> 
 <label> Upload a different file <input type="file" name="foo"> </label>

Once you have the File, you should be able to get a originalName property from it. 获得文件后,您应该可以从中获取originalName属性。 Try $fileName = $request->file('name')->getClientOriginalName(); 尝试$fileName = $request->file('name')->getClientOriginalName(); .

Note: this is untested and I am assuming that both the file() method on the Request object returns an UploadedFile instance and that Laravel's UploadedFile class is either extending Symfony's class or using it directly. 注意:这未经测试,我假设Request对象上的file()方法都返回一个UploadedFile实例,并且Laravel的UploadedFile类正在扩展Symfony的类或直接使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 屏幕上不显示类型文件的输入 - input of type file is not displayed on the screen 如何检查是否选择了文件 <input type=“file”> 在PHP中? - How do I check if a file is selected for <input type=“file”> in PHP? 我如何从查询转换 cakephp 文本 output 以便它显示在输入表单中进行编辑 - how do i convert cakephp text output from a query so that it is displayed in an input form for edit 我如何在服务器端检测输入[type =“ file”]名称( <input type=“file”> )? - how do i detect input[type=“file”] name in server side (<input type=“file”>)? jQuery提交表单输入类型“文件”更改的表单 - Jquery submit form on form input type 'file' change 如何删除输入文件表格上方的标签? - How do I can remove the label above input file form? 如何回显输入类型的文本? - How do I echo the input type text? PHP Multiple输入类型文本和输入类型文件格式输出到数组名称和带有数组Sequence的值 - PHP Multiple Input type Text and input type File form output to array name and Value with array Sequence 如何使用BootForm更改文件类型输入上的“选择文件” - How to change “Choose File” on file type input using BootForm 如何从一个文件中移动一个特定的文件<input type=file multiple>到一个特定的表格里面? - How can I move one specific file from an <input type=file multiple> to inside a specific form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM