<?
// you can change this to any directory you want
// as long as php can write to it
//$uploadDir = 'C:/webroot/upload/';
$uploadDir = '../prod-application/file/';
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$register_id = $_FILES['userfile']['register_id'];
$title = $_FILES['userfile']['title'];
// get the file extension first
$ext = substr(strrchr($fileName, "."), 1);
// generate the random file name
$randName = md5(rand() * time());
// and now we have the unique file name for the upload file
$filePath = $uploadDir . $randName . '.' . $ext;
// move the files to the specified directory
// if the upload directory is not writable or
// something else went wrong $result will be false
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
include 'connectdb.php';
//include 'library/opendb.php';
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$name = $_POST['name'];
$size = $_POST['size'];
$type = $_POST['type'];
$path = $_POST['path'];
$register_id = $_POST['register_id'];
$title = $_POST['title'];
$query = "INSERT INTO upload2 (name, size, type, path,register_id,title ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$register_id', '$title')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
include 'library/closedb.php';
echo "<br>File uploaded<br>";
}
?>
</span>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
<table width="491" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="411" class="style2">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" class="style2" id="userfile" size="50">
</td>
<td width="71" class="style2">
<input name="upload" type="submit" class="style2" id="upload" value=" Upload ">
</td>
</tr>
</table>
<p><span class="style4">Work registration ID: <? echo $register_id;?>
<input name="register_id" type="hidden" id="register_id" value="<? echo $register_id;?>">
<br>
Title of Works: <? echo $title;?>
<input name="title" type="hidden" id="title" value="<? echo $title;?>">
</span> </p>
</form>
<p>
<input name="Submit" type="submit" class="style2" onClick="javascript
:window.close();"value="Close">
</p></td>
</tr>
</table>
Bookmarks