aspose file tools*
The moose likes PHP and the fly likes Error in reading uploaded file name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » PHP
Bookmark "Error in reading uploaded file name" Watch "Error in reading uploaded file name" New topic
Author

Error in reading uploaded file name

R. Joshi
Greenhorn

Joined: Jan 04, 2013
Posts: 22

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
Bartender

Joined: Jul 19, 2004
Posts: 5278
    
  13

What's the value of the enctype attribute of the form tag?


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
R. Joshi
Greenhorn

Joined: Jan 04, 2013
Posts: 22

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
Bartender

Joined: Jul 19, 2004
Posts: 5278
    
  13

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

Joined: Jan 04, 2013
Posts: 22

The error occurs after I upload the image and click on submit button.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5278
    
  13

Hmmm... Can you post the related html and php code snippets?
R. Joshi
Greenhorn

Joined: Jan 04, 2013
Posts: 22

This is the related code, which asks the user to enter the required data and then stores it in the database .



Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5278
    
  13

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

    Joined: Jan 04, 2013
    Posts: 22

    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....
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Error in reading uploaded file name