Notice: Undefined index: userfile

Nov 18, 2004
44
0
0
Why do I get this error on one of my test boxes?
I'm running Apache2 and php5

Notice: Undefined index: userfile in F:\WWW\WWWRoot\GLI\file upload\upload.php on line 14

it works fine on the rest.

heres the code.


<?php
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir = "upload_files/";
$upload_url = $url_dir."/upload_files/";
$message ="";
//create upload_files directory if not exist
if (!is_dir("upload_files")) {
die ("upload_files directory doesn't exist");
}

if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "";
}

print $message;
//
function do_upload($upload_dir, $upload_url) {

$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;

//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
//File Size Check
else if ( $file_size > 20000) {
$message = "The file size is over 2mb.";
return $message;
}
//File Type Check
else if ( $file_type == "text/plain" ) {
$message = "Sorry, You cannot upload any script file" ;
return $message;
}

$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"File uploaded Successfully" :
"Somthing is wrong with uploading a file.";

return $message;
}

//


?>

<table width="661" border="0" align="center" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="661" height="91" valign="top"><form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
<p>Upload Image</p>
<p>
<input name="userfile" type="file" id="userfile" size="50">
</p>
<center> <p>
<input type="submit" name="upload" value="Upload" >
</p></center>
</form>
<a href="www.gfmediacorp.com"> Return Home </a></td>
</tr>
</table>
 

Firus

Senior member
Nov 16, 2001
525
0
0
Edit you php.ini file to not output Notices, as they are usually no big deal.

set (IIRC) error_reporting = E_ALL &amp; ~E_NOTICE instead of just E_ALL.

Unless it is already set to that, then I really dont know :)
 

Beau

Lifer
Jun 25, 2001
17,730
0
76
www.beauscott.com
Check your php.ini error_reporting setting. My guess is that it's different on that one box than it is on the rest.

I have mine set to:
error_reporting = E_ALL &amp; ~(E_NOTICE | E_USER_NOTICE | E_WARNING | E_COMPILE_WARNING | E_CORE_WARNING | E_USER_WARNING) ; display all errors, except notices.