crazy form thing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ale2121
Forum Newbie
Posts: 23
Joined: Tue Aug 23, 2005 9:56 am

crazy form thing

Post 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?
ale2121
Forum Newbie
Posts: 23
Joined: Tue Aug 23, 2005 9:56 am

Post 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 -->
Stewsburntmonkey
Forum Commoner
Posts: 44
Joined: Wed Aug 24, 2005 2:09 pm

Post by Stewsburntmonkey »

You should use the is_uploaded_file() funtion to test if a file has been uploaded. :)
ale2121
Forum Newbie
Posts: 23
Joined: Tue Aug 23, 2005 9:56 am

Post 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 | ..
Post Reply