在 php 中上传文件时遇到问题。-

发布于 2024-07-27 04:37:41 字数 700 浏览 8 评论 0原文

好吧,我遇到了一些非常奇怪的麻烦,这就是发生的事情:

这是环境: 我有一个模式面板,它必须能够容纳几个“步骤”,首先你必须上传一个文件,然后处理该文件,根据这个处理结果,我必须生成一些 html 来填充下一步。

这就是我所做的: 我以两种方式之一在模式面板的表单中上传文件(从某个 url,或使用文件类型输入和 $_FILES 从本地硬盘驱动器),使用 jquery 的 $.ajaxForm 将其提交到 php 文件处理它。 处理后,我将需要的所有对象填充了信息,这些对象在我包含的某些模板中使用,然后将其内容填充到文本变量中,我对它们进行 json_encode,以便附加到我的模式面板的第二个表单中。

到目前为止...一切都很好...直到我发现当我选择“from url”并禁用文件输入时,一切正常,但是当我启用文件输入上传时,我从包含中获得的结果html模板中的内容已损坏(是的...您一定在说 WTF?,但这是真的 0_0 我尝试了一切,直到我隔离了错误隐藏的位置...)。 它在 html 结果的开头添加了一些“PRE”html 标签,每个标签都转换为大写,所有结束标签都有其“<” 和“>” 替换为它的对应实体(如 & lt; 等)。 我通过在表单回调中“警告”原始 HTML 结果(显然是对结果表单造成的损坏)看到了这一点。 关于可能发生的事情有什么想法吗?

提前致谢!!!

PS:我变得冗长了......:P

Well I'm having some really weird trouble, this is what happens:

This is the environment:
I have a modal panel that has to be able to hold several "steps", first you have to upload a file, then the file is processed and from this processing result, I have to generate some html to fill the next step.

This is what I do:
I'm uploading a file within a modal panel's form in either one of two ways (from some url, or from your local hard drive using the file type input and $_FILES), using jquery's $.ajaxForm to submit it to the php file that processes it. Once processed, I have all the objects that I need filled with info, that are used in some template that I include and then with it's contents filled into a text variable I json_encode them in order to be appended into my modal panel's second form.

So far... so good... until I found out that when I choose "from url" and disable file input, everything works just fine, but when I enable the file input upload, the result html that I get from the include from the template is broken (yeah... you must be saying WTF?, but is true 0_0 I tryed EVERYTHING until I isolated where the error was hiding...).
It get some "PRE" html tag added at the beggining of the html result and every tag is cast to upper case and all ending tags have its "<" and ">" replaced by it's entity counterpart (like & lt; and so).
I saw that by "alerting" the raw HTML result in the form's callback (and obviously by the damage caused to the result form).
Any ideas about what can be happening??

Thanks in advance!!!

PS: I got verbose... :P

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卸妝后依然美 2024-08-03 04:37:41

您可能应该提供有关您正在使用的框架/模板引擎的一些详细信息,因为听起来这就是问题所在。 似乎表单的文件输入版本正在使其变得疯狂 - 可能是您必须用于文件上传的 enctype="multipart/form-data" 。 您可以通过将 enctype 属性添加到非文件对话框来测试该部分,然后看看它是否也变得疯狂。

如果您的模板引擎负责,解决问题可能需要升级它或调试其内部。

You should probably give some detail about the framework / templating engine you're using, because it sounds like that's where the problem is. Seems like something about the file input version of your form is driving it insane -- likely the enctype="multipart/form-data" you have to use for file uploads. You could test that part by adding the enctype attribute to your non-file dialog and seeing if it goes insane then too.

If your templating engine is responsible, fixing the problem will probably involve either upgrading it or debugging its guts.

无声静候 2024-08-03 04:37:41

据我所知,你不能像这样使用ajax提交上传。 您可以通过在 中创建一个表单然后提交来伪造它,但我认为您不能使用纯 ajax 来做到这一点。 我是原型用户,但我认为 jquery 或任何其他库也是如此。

As far as I know, you cannot submit an upload with ajax like that. You can fake it by creating a form inside an <iframe> and then submitting it, but I don't think you can use pure ajax to do it. I am a prototype user, but I think the same is true for jquery or any other library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文