简体   繁体   English

通过弹出窗口上传文件PHP

[英]Upload File PHP with popup

Good day, 美好的一天,
I was currently design a form that has 10 fields (3 of them requires upload file while the others are using normal <input> functions). 我目前正在设计一种包含10个字段的表单 (其中3个需要上传文件,而其他则使用正常的<input>函数)。 Here i will only show a sample code for my form with the upload function that will trigger the popup box when the user clicks on the input on the form. 在这里,我将仅显示带有上载功能的表单示例代码,当用户单击表单上的输入时,该函数将触发弹出框。

<form name="form1" action="process.php" method="post">
    <input type="text" id="form_ic" name="form_ic" size="30" onClick="return popup('pdf.php')">
    <a href="javascript:popup('pdf.php')">[Upload]</a>
</form>

For the upload file functions, i will need to do a popup box (pdf.php) from the original form php to show the terms stated for the files to be uploaded (eg. the file must be only .pdf and so on). 对于上传文件功能,我需要从原始形式php中创建一个弹出框(pdf.php),以显示要上传文件的条款(例如,该文件只能是.pdf等)。 The real upload function is only implemented on the form in pdf.php as follows: 真正的上传功能仅在pdf.php中的表单上实现,如下所示:

<form name="pdf_upload" action="index.php" method="post" accept-charset="utf-8" enctype="multipart/form-data">
    <input type="file" name="uploadfile" id="uploadfile">
    <button type="submit" name="submit" value="Upload" onClick="window.close();">Upload</button>
</form>

Here's the catch, 这是要抓的

The purpose for this original form is to register the user profile. 此原始表单的目的是注册用户个人资料。 So what i want to do is that after user select the file from the upload popup box the file will be transferred back to the original form. 所以我想做的是,在用户从上传弹出框中选择文件后,文件将被传输回原始表单。 The name of the file uploaded by the user will be displayed in the <input type="text" id="form_ic"> back in the original form. 用户上载的文件 <input type="text" id="form_ic">以原始格式显示在<input type="text" id="form_ic">中。 The pdf file transferred back to the original form will be submitted along with other field details (eg. name, age, etc). 传输回原始表单的pdf文件将与其他字段详细信息(例如姓名,年龄等)一起提交。 For your information, since there are 3 fields using the same upload function with popup, I will implement the same popup function. 供您参考,由于有3个字段使用带有弹出窗口的相同上载功能,因此我将实现相同的弹出功能。

I'm stuck of transferring the pdf file from the popup php to the original form php and to display the name of the uploaded file back in the original form php. 我陷入了将pdf文件从弹出php传输到原始形式php的问题,并以原始形式php显示上传文件的名称。 I really need opinions from the community to solve this problem. 我真的需要社区的意见来解决这个问题。

I am well aware that to display the name of .pdf file to the <input> , you'll require the javascript .innerHTML function, but i just can't retrieve the uploaded .pdf file from the pdf.php. 我很清楚,要在<input>显示.pdf文件的名称,您将需要javascript .innerHTML函数,但我只是无法从pdf.php中检索上载的.pdf文件。 It may be due to the problem with my code design. 这可能是由于我的代码设计问题所致。 I'm not sure whether AJAX is required for my problem. 我不确定我的问题是否需要AJAX。 Please help me. 请帮我。

Thank you. 谢谢。

Most of your code is right, but you need to make change in your approach. 您的大多数代码是正确的,但是您需要对方法进行更改。

First, from your pop-up (pdf.php), you should upload the file. 首先,您应该从弹出式窗口(pdf.php)中上传文件。 Currently you are calling 'window.close' , hence the file is not submitted and upload functionality is not happening. 当前,您正在调用'window.close' ,因此该文件未提交且上传功能未发生。 While the modal box(Pop-Up) is open, let the file be uploaded and then through ajax, check if it is successful. 在模式框(Pop-Up)打开的同时,先上传文件,然后通过Ajax检查文件是否成功。 If yes, then you can return the name of the file that it is saved as on server. 如果是,则可以返回在服务器上另存为的文件名。 This file name, you can pass to your main Form (Field should be Un-editable) 此文件名,您可以传递到主窗体(字段应为不可编辑)

Second, you should change your JS code such that whenever you call the Pop-Up, you send the ID of the TextField of the Main Form, so that after file upload, the javascript sends the filename to the same field. 其次,您应该更改JS代码,以便每当调用弹出窗口时,都发送主窗体的TextField的ID,以便在文件上传后,javascript将文件名发送到同一字段。

If you need more codebased example, then you should refer this example http://www.web-development-blog.com/archives/upload-in-modal-window-and-pass-values-with-jquery/ 如果您需要更多基于代码的示例,则应参考以下示例http://www.web-development-blog.com/archives/upload-in-modal-window-and-pass-values-with-jquery/

Demo page of the above example can be found at: http://www.finalwebsites.com/demos/modal_upload_jquery_thickbox.php 上面示例的演示页面可以在以下位置找到: http : //www.finalwebsites.com/demos/modal_upload_jquery_thickbox.php

Hope this helps to solve your problem. 希望这有助于解决您的问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM