当我尝试上传文件时出现错误?
我不断收到错误:通知:未定义索引:位于第 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新: OP 正在执行 Ajax 请求 - 显然这不能用于文件上传。
旧答案:
我想我找到了。
仔细看看这个标签:
关闭
/>
关闭表单。之后出现的所有内容都不在该表单内 - 它位于浏览器可能生成的新表单内处理损坏的标记。该新表单不是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:
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 notenctype=multipart/form-data
.您是否在表单元素上使用了
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
为了使用 ajax 提交上传,您可以使用带有上传部分的 IFRAME。
有点复杂,但可以工作。您需要某种机制将它们绑定在一起,例如,如果您要提交有关图像的信息,请在步骤 1 中返回存储该信息的数据库行的 id,以便 IFRAME 上传表单可以提交该 id,以便它知道在哪里来存储图片。
In order to upload WITH an ajax submission you can use an IFRAME with the upload part in there.
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.