0

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?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by awestove
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.