what's wrong in my code?
Posted: Wed Jun 18, 2008 4:43 am
what's wrong in my code? bec. when i trying to add attachment it is always failed. i cant add to database also the path directory..
Code: Select all
<?
if(isset($_POST['upload']))
{
$file['file']=$_FILES['file']['tmp_name'];
$file['size']=$_FILES['file']['size'];
$ext='';
$file['extent'] = pathinfo(strtolower($_FILES['file']['name']));
$file['name']=(isset($file['extent']['extension'])) ? strtolower($user.".".$file['extent']['extension']) : '';
$uploadDir = 'my directory';
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.$file['name']);
}
}
//db
$query = "INSERT INTO upload (name, size, type, path) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed :' . mysql_error());
?>
<form action="" method="post">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="file" type="file" class="box" id="file">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value="Upload"></td>
</tr>
</table>
</form>