Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in reading uploaded file name

 
R. Joshi
Greenhorn
Posts: 22
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to PHP and learning PHP using Head First, as said in the chapter to upload a file I declared in HTML:

<input type = "file" name = "screenshot" id = "screenshot" />

And tried to read the name of the uploaded image file via PHP by:

$screenshot = $_FILES['screenshot']['name'];

but when I tried to upload a file following error occurs:

" Notice: Undefined index: screenshot in C:\xampp\htdocs\test\addscore.php on line 14 "

Kindly help me in finding the real cause as the index that is mentioned is same in both i.e. screenshot, also the size of the file is small then the declared max size.
 
Roel De Nijs
Sheriff
Posts: 9927
111
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the value of the enctype attribute of the form tag?
 
R. Joshi
Greenhorn
Posts: 22
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:What's the value of the enctype attribute of the form tag?


The enctype is "multipart/form-data".
 
Roel De Nijs
Sheriff
Posts: 9927
111
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks ok! And you are using method="post" too?

And when does the error occur? When you 1st visit the upload page? Or after hitting the submit-button? Or...?
 
R. Joshi
Greenhorn
Posts: 22
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error occurs after I upload the image and click on submit button.
 
Roel De Nijs
Sheriff
Posts: 9927
111
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... Can you post the related html and php code snippets?
 
R. Joshi
Greenhorn
Posts: 22
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the related code, which asks the user to enter the required data and then stores it in the database .



 
Roel De Nijs
Sheriff
Posts: 9927
111
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used your code and gave it a try: no problems for me at all. File uploaded without any notice. Weird!

2 (unrelated) remarks though:
  • you should use <br> or <br />, not </br>
  • maybe you can change logic to show the output form: initialize $output_form with true before the 1st if and set it to false when needed (will save you several lines)


  • I'm using a standard xampp installation (version 1.8.3).
     
    R. Joshi
    Greenhorn
    Posts: 22
    Java MySQL Database Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I just re-installed my XAMPP and the code worked.......might be some problem with XAMPP server as all things you said were fine.

    Thanks a lot for going through my " difficult to read " code and helping Roel De Nijs....
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic