I cant upload my file whats seems to be the problem with this code, i keep getting message file is empty....
<?
function upload_form(){
global $PHP_SELF;
?>
<form name="add" method="post" action="<?php echo $PHP_SELF ?>" ENCTYPE="MULTIPART/FORM-DATA" >
<table width="792" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3">
<div align="center">
<hr>
<font size="2" face="Arial, Helvetica, sans-serif"><b></b></font></div>
</td>
</tr>
<tr>
<td width="158">Partners Name</td>
<td width="317">
<input type="text" name="partners_name">
</td>
<td width="317"> </td>
</tr>
<tr>
<td valign="top" width="158">Image to be uploaded</td>
<td width="317">
<input type="file" name="name">
</td>
<td width="317"> </td>
</tr>
<tr>
<td valign="top">Writeup</td>
<td>
<textarea name="body" cols="50" rows="10"></textarea>
</td>
<td> </td>
</tr>
<tr>
<td width="158">
<input type="hidden" name="action" value="upload">
<input type="reset" name="Submit2" value="Reset">
<input type="submit" name="Submit" value="Upload">
</td>
</table>
<p> </p>
</form>
<?
}
function upload_file(){
global $userfile, $userfile_name, $userfile_size, $userfile_type, $WINDIR;
//Attemp to check platform if Windows change to double back slash
if(isset($WINDIR)) $userfile = str_replace("\\\\","\\", $userfile);
//$max_filesize = 65536;
//Read filename directory path and return filename only
$filename = basename($userfile_name);
echo $filename;
//Check if filename if empty
if($userfile_size <= 0) die ("$filename File is empty");
//Attempt to copy filename to temporary directory
if(!@copy($userfile, "temp/$filename"))
die("Can't copy $userfile_name to $filename");
echo "File : $filename has been succcesfully uploaded. <BR>";
echo "Filesize : " . number_format($userfile_size) ."<BR>";
echo "Filetype : $userfile_type <BR>";
//Attempt to connect to MySQL server
$link = mysql_connect("192.168.10.106","joseph","joseph123");
// If connection failed...
if (!$link) {
// Inform user of error and quit
print "Couldn't connect to database server";
exit;
}
// Attempt to select database
if(!@mysql_select_db(Mdi)) {
// Inform user of error and exit
print "# Couldn't select database <br>\n";
exit;
}
// Build Query
$image = addslashes(fread(fopen("temp/$filename","rb"), filesize("temp/$filename")));
if (!$image) die ("Cannot open file");
echo $image;
$query = "INSERT INTO partners(image)
VALUES($image)";
echo $query."<br><br>";
// Execute Query
$result = @mysql_query($query);
// Close the connection
mysql_close($link);
}
?>
<HEAD><TITLE>UPLOADING WINDOW</TITLE></HEAD>
<BODY>
<?
if ($action == 'upload')
upload_file();
else upload_form();
?>
</BODY>