Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Input type="file" problem?

Status
Not open for further replies.

Chris1701

MIS
Dec 27, 2004
33
US
I maintain our company website and we had upgraded our web server to a VPS plan from our previous shared plan so that we could install a specific search engine. While this worked fine and we got what we wanted, we also got newer / updated versions of some of the other software on the server i.e. newer Apache, MySql and PHP. The end result was that a number of things that worked before became "broken", the biggest problem was that on the previous version all PHP variables had been global and now everything was made local. While I believe this is an option on the server that could be set back to the old settings prevailing opinion seems to be that for security this is a better option. I mention all of this just so that you can understand the history of this problem.

Within the content management portion of out site there are several pages where you can add / edit / delete data from the MySql database. All of these pages use the HTML FORM element and various input fields. In several of the pages there are fields that use the "file" type field to specify images files to be upload to the site. The problem is that all the fields are properly passing back their values to the page specified in "action" with the exception of these "file" fields. As far as my testing goes once the "submit" button is pressed and control passes to the pages specified the value of these file fields is blank while all the other fields have the values that were input on the previous page. Here's a snipit of code from the page that I'm trying to fix:
Code:
<form action="index.html" method="post" enctype="multipart/form-data" >
<input type="hidden" name="table" value="<? echo "njhs_".$tablename ?>">
<input type="hidden" name="recid" value="<? echo $_GET["recid"] ?>">
<input type="hidden" name="action" value="updatedb">
<input type="hidden" name=assetPath value = "/home/webadmin/mywebsite/html/assets">
<h2><? echo $PageTitle ?></h2>

<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td>
			Title: 
		</td>
		<td colspan="2">
			<input type="text" size=100 name="sf[title]" value="<? echo $RowDat["title"] ?>">
		</td>
	</tr>
	<tr>
		<td>
			Small Image:&nbsp;&nbsp;
		</td>
		<td valign="middle">
			<input type="file" name="upfile_small" size = "80">&nbsp;&nbsp;&nbsp;
		</td>
			<?
			if ($_GET["recid"]) {
				echo "<td valign=\"middle\"><font size=\"2\">Current Image:</font><br><img src=\"../assets/njhs_exhibits/small_image_file/" . $RowDat["small_image_file"] . "\"></td>\n";
			} else {
				echo "<td>&nbsp;</td>\n";
			}
			?>
	</tr>
	<tr>
		<td colspan="3">
			&nbsp;
		</td>
	</tr>
	<tr>
		<td valign="middle">
			Large Image:&nbsp;&nbsp; 
		</td>
		<td>
			<input type="file" name="upfile_large" size = "80">&nbsp;&nbsp;&nbsp;
		</td>
			<?
			if ($_GET["recid"]) {
				echo "<td valign=\"middle\"><font size=\"2\">Current Image:</font><br><img src=\"../assets/njhs_exhibits/large_image_file/" . $RowDat["large_image_file"] . "\"></td>\n";
			} else {
				echo "<td>&nbsp;</td>\n";
			}
			?>
	</tr>
	<tr>
		<td colspan="3">
			&nbsp;
		</td>
	</tr>
</table>
</form>

As you can see the enctype is correct and the fact that the other fields work and the file fields don't is really driving me a little crazy. Does anyone have an idea why these particular fields are not passing their values back?
 
Perhaps asking in the PHP forum to see if there were any changes between versions X and Y to do with file inputs might be a better bet? It doesn't sound like an HTML issue to me.

Obviously, X and Y are meant to be whatever your old and new version numbers are :)

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan:
I thought about posting this in the Php forum but that didn't seem right. The FORM element and passing values through the POST method are really straight HTML aren't they? It does seem strange to me that in large part the problems were caused by the updated Php (and settings on the server being different) but Html really hasn't changed, I mean Html hasn't changed like Php has? I've tried googling this and I haven't been able to turn up any idea's and I was hoping that someone here could point me in a new direction.
 
I agree with Dan. This has nothing to do with HTML. Especially since you have not changed the code at all. HTML will surely prepare everything to send the file to the PHP script and it is PHP that is rejecting the file (for whatever the reason is). That is why you will get more help in the forum434.

However, do you know that uploaded files are inside the $_FILES array and not the $_POST array?

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
I also concur with the guys and say you should ask this in the PHP forum Probably the update changed a value in the PHP.ini file of the server limiting the size of the uploaded files.

You would need to alter that setting. But again this is a PHP question so you would be better off asking in: forum434

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I'll have to test that, but nowhere in either of the HTML and PHP books that I have does it mention that in a form element using POST the input type "File" is passed back in the $_Files array and not the $_Post array. That is almost certainly the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top