当我尝试上传文件时出现错误?

发布于 2024-10-10 06:50:22 字数 680 浏览 0 评论 0原文

我不断收到错误:通知:未定义索引:位于第 35 行

第 35 行:

 $handle = new Upload($_FILES['my_field']);

这是我的输入字段

 <input type="file" size="32" name="my_field" value="" />

我不明白此错误,谢谢!

编辑:

 <form name="upload" id="upload" enctype="multipart/form-data" method="post" action="actions/upload.php" />
 <p><input type="file" size="32" name="my_field" value="" /></p>
 <p class="button"><input type="hidden" name="action" value="image" />
 <br>
 <input style="margin-left:224px;" type="submit" name="submit" value="upload" />

I keep getting an error:Notice: Undefined index: on line 35

line 35:

 $handle = new Upload($_FILES['my_field']);

this is my input field

 <input type="file" size="32" name="my_field" value="" />

I do not understand this error, thanks!!!

EDIT:

 <form name="upload" id="upload" enctype="multipart/form-data" method="post" action="actions/upload.php" />
 <p><input type="file" size="32" name="my_field" value="" /></p>
 <p class="button"><input type="hidden" name="action" value="image" />
 <br>
 <input style="margin-left:224px;" type="submit" name="submit" value="upload" />

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

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

发布评论

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

评论(3

空城之時有危險 2024-10-17 06:50:22

更新: OP 正在执行 Ajax 请求 - 显然这不能用于文件上传。

旧答案:

我想我找到了。

仔细看看这个标签:

 <form name="upload" id="upload" enctype="multipart/form-data" method="post"
 action="actions/upload.php" />

关闭 /> 关闭表单。之后出现的所有内容都不在该表单内 - 它位于浏览器可能生成的新表单内处理损坏的标记。该新表单不是 enctype=multipart/form-data

Update: The OP is doing an Ajax request - well that obviously can't work with a File upload.

Old answer:

I think I found it.

Look closely at this tag:

 <form name="upload" id="upload" enctype="multipart/form-data" method="post"
 action="actions/upload.php" />

the closing /> closes the form. Everything that comes afterwards, is not inside that form - it's inside a new one that the browser probably generates to deal with the broken markup. That new form is not enctype=multipart/form-data.

幸福还没到 2024-10-17 06:50:22

您是否在表单元素上使用了 enctype="multipart/form-data"

这似乎是未在 $_FILES 上设置键 my_field 的唯一原因。

编辑:如果您的文件大于 post_max_size,您还会得到一个空的 $_FILES 数组。

另请参阅:Apache/PHP:$_FILES数组神秘地为空

Did you use enctype="multipart/form-data" on the form element?

This seems to be the only reason that the the key my_field isn't set on $_FILES.

Edit: If your file is bigger than post_max_size, you also get an empty $_FILES array.

See also: Apache/PHP: $_FILES Array mysteriously empty

厌倦 2024-10-17 06:50:22

为了使用 ajax 提交上传,您可以使用带有上传部分的 IFRAME。

  1. 发送ajax表单提交
  2. 在IFRAME中的上传表单上使用javascript触发submit()
  3. 让iframe中的返回页面触发主页中的javascript完整响应功能

有点复杂,但可以工作。您需要某种机制将它们绑定在一起,例如,如果您要提交有关图像的信息,请在步骤 1 中返回存储该信息的数据库行的 id,以便 IFRAME 上传表单可以提交该 id,以便它知道在哪里来存储图片。

In order to upload WITH an ajax submission you can use an IFRAME with the upload part in there.

  1. Send ajax form submission
  2. Using javascript trigger submit() on the upload form in the IFRAME
  3. Have the returning page in the iframe trigger a javascript complete response function in the main page

A bit complicated but would work. You would need some mechanism to tie them together, for instance if you are submiting info about the image, have step 1 return the id of the database row where that info is stored so that the IFRAME upload form can submit that id so it knows where to store the picture.

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