Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ Input type file not working, why?

Posted by: Gerry Roston May 4 2022, 09:53 PM

I am beyond confused. Here is a some of my html code (which I copied using my browser’s ‘show source’ capability). Very simple.

CODE
<div style="width: 40%; float: right;">
  <label style="position: absolute; top: 250px;">File with new logo:</label>
  <input style="position: absolute; top: 280px;" type="file" name="LogoFile">
</div>

In my code, I have some PHP to gather the data that is inputted and store it in a database. The code works just fine. However, I added two lines to the code:
CODE
echo "checking filename:  ";
echo $_FILES['LogoFile']['name'];

and the filename comes back empty, despite my having selected a file. Even weirder, the code used to work, but only stopped working once I moved the code into the <div> and added the style stuff. I suspect that I am missing something trivially easy – can you please point me to a solution.

Posted by: Christian J May 5 2022, 08:55 AM

QUOTE(Gerry Roston @ May 5 2022, 04:53 AM) *

I added two lines to the code:
CODE
echo "checking filename:  ";
echo $_FILES['LogoFile']['name'];

and the filename comes back empty, despite my having selected a file.

Looks correct to me. Could it be that the above lines are in the wrong place in the PHP script?

QUOTE
Even weirder, the code used to work, but only stopped working once I moved the code into the <div> and added the style stuff.

I see no reason for that.

(As a sidenote, I wouldn't use CSS absolute positioning like that, also I wouldn't use CSS as nline styles for practical reasons).

Posted by: Christian J May 5 2022, 11:29 AM

Seems the thread got closed by mistake. Opened now. blush.gif

Posted by: pandy May 5 2022, 11:58 AM

When you moved the code, did you include the PHP tags?

Posted by: Gerry Roston May 5 2022, 05:51 PM

I found my stupid mistake! I had put the new <div> code outside of the <form> tag. Once I adjusted that, everything worked fine.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)