1

I have a HTML page,where file input type is defined. but when i try uploading it, its not working using move function. then found that, echoing file name itself not printing anything after selecting any file...

HTML:

<form id="upload_items" name="upload_items" method="post" action="items.php">
  <input type="file" name="itemlist_file" id="itemlist_file" />
  <br />  <br />
  <input type="submit" name="Upload" value="Upload" id="Upload" />
  </form>

Form submission php page:

error_reporting(E_ERROR | E_PARSE);
echo (basename($_FILES["itemlist_file"]["name"])

Output:

Nothing displayed...

6
  • 1
    Is Form submission page the items.php file? Commented Feb 9, 2014 at 9:55
  • 3
    You must add enctype='multipart/form-data' to your forms attributes. Commented Feb 9, 2014 at 9:56
  • yes it is... i am wondering Commented Feb 9, 2014 at 9:56
  • @logan - That seems very strange. The only thing that seems incorrect is that you forgot to add this attribute. Commented Feb 9, 2014 at 9:58
  • 1
    i think enctype is main issue and you can also see full example file upload in php from here : php.net/manual/en/features.file-upload.post-method.php Commented Feb 9, 2014 at 9:59

2 Answers 2

4

You forgot to provide the correct enctype which is obligatory for uploads. Add the enctype attribute to your form like:

<form id="upload_items" name="upload_items method="post" action="items.php" enctype="multipart/form-data"> ...
Sign up to request clarification or add additional context in comments.

Comments

1

You need to add this to the form :-

enctype='multipart/form-data'

enctype='multipart/form-data is an encoding type that allows files to be sent through a POST. Quite simply, without this encoding the files cannot be sent through POST.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.