I am trying to create a file upload form on a website and am getting the error:

Notice: Undefined index:

My code is:

<?php
session_start();

if (isset($_GET['submitted'])){
	print_r($_FILES);
	$displayName = $_GET['displayName'];
	//file name is name of user who uploaded-date-time ie awestove-20100901-0800
	$fileName = $_GET['username']."-".date('Ymd-Hi');
	$origFileName = $_FILES['fileChooser']['name'];
	$ext = end(explode(".", $origFileName));
	$targetPath = "uploads/";
	$targetPath = $targetPath . $fileName . $ext;
	if(move_uploaded_file($_FILES['fileChooser']['tmp_name'], $targetPath)) {
		echo "The file ".  basename( $_FILES['fileChooser']['name']). 
			" has been uploaded";
	} else{
		echo "There was an error uploading the file, please try again!";
}

}
else {
?>

<form enctype='multipart/form-data' name="addFile" id="addFile" action="<?php echo $_SERVER['PHP_SELF']."?completed=true";?>"
	method="post" onSubmit="return checkInputErrors('addFile','ajax/addFile.php')">
	<div class='formContainer'>
		<div class='inputContainer'>
			<div class='label' id='displayNameLabel'>Name to Display:</div>
			<div class='textEntry'>
				<input type='text' name='displayName'/><br />
			</div>
			<div class='text'>
				<input type="hidden" name="username" value="<?php echo $_SESSION[$appId]['userId']?>" />
			</div>
		</div>
		<div class='inputContainer'>
			<div class='label' id='fileChooserLabel'>File to Upload:</div>
			<div class='textEntry'>
				<input name='fileChooser' id='fileChooser' type='file' size='40' /><br />
			</div>
		</div>
		<div class='inputContainer'>
			<div class='submitButton'>
				<input type='submit' name='submit' value='Submit' />
			</div>
		</div>
	</div>
</form>

<?php
}
?>

In my HTML form I have

<input name='fileChooser' id='fileChooser' type='file' size='40' /><br />

but in the php section it says that 'fileChooser' is an undefined Index. print_r and var_dump tell me that $_FILES is an empty array. I'm at a loss, any help?

Works good for me...
I have noticed $appId variable. Maybe you are using it for a Facebook application?

Works good for me...
I have noticed $appId variable. Maybe you are using it for a Facebook application?

Not facebook, designing web apps for my University. appId is something for the main web server that houses all the web apps. Think I'll have to mess with some php.ini settings, see if that fixes it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.