简体   繁体   English

Ajax jQuery图片上传-新手问题最好的处理方法是什么?

[英]Ajax jQuery picture upload - newbie question whats the best way to handle this?

I have a page with a form on it that the user visits to fill in some info before he signs up for a profile. 我有一个带有表单的页面,用户在注册个人资料之前会先访问该表单以填写一些信息。 Underneath the form is a preview of what the profile will look like. 表单下方是配置文件外观的预览。 I have some javascript so that as the user types into the boxes in the form, the corresponding bit of their profile fills with whatever they're typing. 我有一些JavaScript,因此当用户在表单中的框内输入内容时,其个人资料的相应位将填入他们所输入的内容。 IE they type into the 'title' form input and it will appear in the id="title" div below. 即,他们在“标题”表单输入中键入内容,它将显示在下面的id =“ title” div中。

In that form I also have a field so the user can upload a photograph. 在该表格中,我还有一个字段,以便用户可以上传照片。 When the user chooses the pic he wants to upload and closes the dialog, I'd like a resized (so that it fits my max height/width requirements) image to also appear in the preview bit below the form. 当用户选择要上传的图片并关闭对话框时,我希望调整大小(以使其符合我的最大高度/宽度要求)图像也显示在表单下方的预览位中。 All this would happen before the profile form had been submitted. 所有这些都将在提交个人资料表格之前发生。

Whats the best way to go about this? 最好的方法是什么? I've done a fair bit of googling and while there's plenty of plugings they all seem to either do something far too complicated or miss something out. 我做了很多的谷歌搜索,尽管有很多插件,但它们似乎都做得太复杂了或者错过了一些东西。 Can anyone please tell me the best way to handle this? 谁能告诉我解决这个问题的最佳方法?

Thanks :) 谢谢 :)

If it makes any difference I'm using cakephp. 如果有什么不同,我正在使用cakephp。

Side question - is there a way to make sure that when the choose file dialog opens, there is only the option to select image file types. 附带的问题-有一种方法可以确保打开“选择文件”对话框时,只有选择图像文件类型的选项。 IE all the .doc .xlt etc aren't there? IE浏览器中所有的.doc .xlt等都不存在吗?

As to your first question, you'll have to upload the file. 关于第一个问题,您必须上传文件。 So you'd upload the image and store it in a temporary location that you can still stream back in an IMG element. 因此,您将上传图像并将其存储在一个临时位置,您仍然可以将其流回IMG元素。 When the user saves the form, you can then discard the temp image. 当用户保存表单时,您可以丢弃临时图像。 You'll probably also need some sort of cron/scheduled task that cleans them up if folks never save the information and just leave. 如果人们从不保存信息而只是离开,您可能还需要某种cron /计划任务来清理它们。

As to your second question, nope. 关于第二个问题,不。 You can check it on the client after they have selected a file, but then I strongly recommend checking it again on the server. 他们选择文件后,可以在客户端上对其进行检查,但是我强烈建议您在服务器上再次对其进行检查。

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

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