上传图片形式与另一种填充式窗体窗体、上传图片、形式

2023-09-10 17:28:24 作者:成熟小男人

我所拥有的是一个像姓名,地址......而另一个单独的上传用户照片的形式详细信息的表格。我想这(可选)上传图片时,父(独立的)的形式提交。 现在他们的工作是这样的: 上传PIC通过 .ajaxSubmit发送()来process_uploaded_image.php。然后,它得到处理,调整大小,而新画面中的转储/ TEMP文件夹中进行。我可以返回它成功:功能(数据),在数据的形式,可以在回荡 $ image_path_and_name 或作为< IMG SRC =$ image_path_and_name/> 。我做了这样 - 这,是有一个临时的图像 - 因为(1)我想允许用户查看他刚才上传的(记​​得我已经拥有它返回的路径或img元素jQuery的,我可以把它无论我想要的),和(2)上传的图像不是最终的,直到父的形式最终完成注册。而且它仍然是一个临时的图像毕竟。 因此,问题的我要访问上载的图像,而把它一起与父的形式,当它被提交 ...我怎么能这样做到底是什么?技术上讲,它不是一个父窗体,因为我知道,在形式的形式是不允许的。但它绑起来,并根据该家长形成逻辑。我将感谢任何帮助,但如果可能的话,我会AP preciate甚至更多,如果你能考虑我的present情景,所以我不必从头开始。再次感谢。 我的想法:(请让我知道如何可行的,这是...和/或指导我如何能做到#1) 1,重建或复制从阿贾克斯,jQuery的文件返回 $ image_path_and_name 字符串(数据)或者< IMG SRC =$ image_path_and_name /> ,把它放在最后的上传文件夹中的<!---这是我难倒我不能只使用 move_uploaded_file()以,可以吗? 2.因为,从这一点上一切都final..I可能的文件路径保存到我的数据库,以及其他形式的信息。 3.清空转储/ temp文件夹。

What I have is a form with details like name, address...and another separate upload profile pic form. And I want to get that (optional) uploaded picture when the "parent" (separate) form is submitted. Right now they work like this: Uploaded pic is sent through .ajaxSubmit() to process_uploaded_image.php. Then it gets processed, resized, and the new picture is made within a "dump/temp" folder. I could return it in success: function(data), in the form of data that could be the echoed $image_path_and_name or as an <img src="$image_path_and_name"/>. I made it this way - that, is having a temp image - since (1) I want to let the user view what he just uploaded (remember I already have it returned path or img element to jquery and I could place it anywhere I want), and (2) the uploaded image isn't final, not until the "parent" form finalizes the registration. And it is still a temp image after all. So, the problem is: I want to access that uploaded image, and "bring it along" with the "parent" form when it gets submitted...how can I do that exactly? Technically it isn't a parent form, since I know a form within form is not allowed. But it is tied up and under that parent form logically. I would be thankful for any help, but if possible, I would appreciate it even more if you could consider my present scenario so I won't have to start from scratch again. Thanks again. My idea: (please let me know how feasible this is...and/or guideline on how I could do #1) 1. "reconstruct" or copy that file from ajax-jquery returned (data) of $image_path_and_name string or <img src="$image_path_and_name"/>, place it in final upload folder.<---THIS IS WHERE I'M STUMPED! I couldn't just use move_uploaded_file(), can I? 2. Since, from this point everything's final..I could save its file path to my database, along with other form info. 3. empty the dump/temp folder.

推荐答案

我的解决办法是,使用一个IFRAME上传,并在​​iframe返回页面使用JavaScript这样

My solution is that using a iframe for upload, and using JavaScript like this in the return page of the iframe

echo("<script type=\"text/javascript\">parent.insert('". $WHAT_YOU_WANT . "');</script>");

和功能插入在父页面定义,可以插入串入,你想要的。 obj_ta 是目标文本框,或别的东西。

and the function insert is defined in the parent page, and can insert the string into the where you want. obj_ta is the target textfield, or something else.

//A simple input
function insert(str) {
    obj_ta.value = str;
}

//A textfield which accept some other user inputs
function insert(str) {
var startPos = obj_ta.selectionStart,
    val = obj_ta.value;
obj_ta.value = val.substring(0, startPos) + str + val.substring(startPos, obj_ta.value.length);
}