i got a undefined index error when file upload in php

北城以北 提交于 2019-12-04 06:04:24

问题


i searched again and again but could not find the right answer. here is the situation. i got more than one forms in the same php file and below shows the code.

when i echo as below

echo count($_FILES["fileUploadPath"] );

it shows 0 as the count and

Notice: Undefined index: addProjectFileUploadPath in C:\wamp...

updated: probelm solved..... error came due to 3rd party jquery plugin called "fileinput"


回答1:


add enctype="multipart/form-data" to the form




回答2:


Try looking at the entire array with this:

echo "<pre>".print_r($_FILES,true)."</pre>";

Then use this manual page to let you know what the error numbers mean. That will probably give you a good idea of what is going on.

PHP File Upload Error Codes




回答3:


Okay, there are a couple of things you need to be aware of.

1) You can have as many forms on a page as you want, but you can only submit one of them. You need to make sure the form you expect is being submitted. I'm assuming you're using the submit button names for doing this. However this can result in problems if someone submits the form by hitting enter in a text entry region, the button won't be submitted. A hidden field would be better as it would always be submitted.

2) There doesn't seem to be a MAX_FELE_SIZE form input anywhere in your file upload form. File uploading will not work without it. You need to put something like <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> before the file inputs on your form.




回答4:


I had the same problem before and I noticed that It happens when I don't close the tags, so try closing all input tags like this:

<form action='upload.php' method="post" enctype="multipart/form-data">
<!-- at the end of the input add / -->
<input type='file' name='file'  />
<input type='submit' name='upload' />
</form>


来源:https://stackoverflow.com/questions/5280645/i-got-a-undefined-index-error-when-file-upload-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!