This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Error in reading uploaded file name

 
Greenhorn
Posts: 22
Oracle MySQL Database Java
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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
Oracle MySQL Database Java
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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
Oracle MySQL Database Java
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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
Oracle MySQL Database Java
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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
    Oracle MySQL Database Java
    • 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....
     
      Bookmark Topic Watch Topic
    • New Topic