Page 1 of 1

crazy form thing

Posted: Wed Aug 24, 2005 4:36 pm
by ale2121
i have this bit of code:

Code: Select all

if (isset($_POST['upload'])) {
		$u = TRUE;
	} else {
		$u = FALSE;
		$message .= '<p>Please select a file to upload!</p>';
	}
the following line after that is
if ($u) {
upload file;
}
i keep getting "please select a file to upload!" on my page, but $u apparently returns true becuase it's moving past the next if statement and uploading the file perfectly.
I'm wondering if i'm testing this for incorrectly...what would the correct syntax to check that a file (browse) form has been filled?

Posted: Wed Aug 24, 2005 5:10 pm
by ale2121
ok so the uploading the file anyway thing, i figured that out, but now it's getting stuck here... like it should (i guess)
my guess is that I'm not validating the file form correctly?

this form:

<form enctype = "multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>

<p><b>Band/Artist:</b> <input type="text" name="band_name" size="15" maxlength="15" value="" /></p>

<p><input type = " hidden" name = "MAX_FILE_SIZE" value = "2000000"/><b>select file:</b> <input type = "file" name = "upload" value = ""/></p>
</fieldset>

<div align="center"><input type="submit" name="submit" value="Register" /></div>

</form><!-- End of Form -->

Posted: Wed Aug 24, 2005 5:17 pm
by Stewsburntmonkey
You should use the is_uploaded_file() funtion to test if a file has been uploaded. :)

Posted: Wed Aug 24, 2005 8:46 pm
by ale2121
fixed.

Code: Select all

if (isset($_FILES['upload']['name'])) {
		$u = TRUE;
	} else {
		$u = FALSE;
		$message .= '<p>Please select a file to upload!</p>';
sorry that was a really easy answer. also, the strange part is that this also fixed a problem where my hidden form tag was not hiding.


feyd | ..