<?
// CREATE A DB/TABLE HERE MAY BE NEEDED TO BE CHANGED ONCE TO Y
// THEN TURNED BACK TO N
$create_db = "N";
$create_table = "N";
// URL - MAY NEED TO BE INSERTED MANUALLY
$url = $HTTP_SERVER_VARS["SERVER_NAME"];
//$url = "http://www.mydomain.com";
// ROOT LOCATION OF WEBSITE (may need to be altered )
$rootdir = $HTTP_SERVER_VARS["DOCUMENT_ROOT"];
//$rootdir = "/home/sites/site/web";
// DIRECTORY NEEDS TO BE 666 AND OFF YOUR ROOT DIRECTORY
$directory = "uploads";
// (another example: $directory = "uploads/photos/name";
// TITLE OF PAGE
$title = "Web Group Media Upload";
// Maximum Size of File
$maxsize = "300000";
// DATABSE INFORMATION
$dbhost = "localhost";
$dbuser = "user";
$dbpass = "pass";
$db = "uploadtest";
$dbtable = "uploadtest";
// MYSQL CONNECT
mysql_connect("localhost","$dbuser","$dbpass");
/// END OF EDIT NEEDED
// TABLE NEEDED IN DAtABASE
// WITH THREE FIELDS ONLY !
// id INTEGER AUTO_INCREMENT PRIMARY KEY
// description char(255)
// filename char(128)
// CREATE TABLE
if ($create_db == "Y"){
if (mysql_create_db("$db")) {
print ("Database created successfully\n");
} else {
printf ("Error creating database: %s\n", mysql_error ());
}
}
if ($create_table == "Y"){
$createtable = "CREATE TABLE $db.$dbtable (id INTEGER AUTO_INCREMENT PRIMARY KEY,description char(255),filename char(128))";
if (mysql_query("$createtable")) {
print ("Table created successfully\n");
} else {
printf ("Error creating table: %s\n", mysql_error ());
}
}
// SELECT DB
mysql_select_db("$db")
or die("Could not select database");
// THE HEADER OF PAGE
echo "
<html>
<head>
<title>$title</title>
<style type='text/css'>
BODY {font-family: Verdana, Helvetica, Arial; font-size: 8pt;}
TD {font-family: Arial, Helvetica; font-size: 10pt;}
INPUT {font-family: Arial, Helvetica; font-size: 10pt;}
A:link {text-decoration: underline; color: #003030;}
A:visited {text-decoration: underline; color: #002020;}
A:hover {text-decoration: none; color: #009090;}
TEXTAREA {font-family: Arial, Helvetica;font-size: 10pt;height: 200px; width: 600px;}
</STYLE>
</head>
<body>";
// DELETE FILE FUNCTION
function delfile($file) {
$delete = @unlink($file);
if (@file_exists($file)) {
$filesys = eregi_replace("/","\\",$file);
$delete = @system("del $filesys");
if (@file_exists($file)) {
$delete = @chmod ($file, 0775);
$delete = @unlink($file);
$delete = @system("del $filesys");}}}
// CHECK TO SEE IF DELETE IS ACTIVATED
if (isset($D)){
$result=mysql("$db","SELECT * from $dbtable where id='$I'");
$value = mysql_fetch_row($result);
$F = "$rootdir/$directory/$value[2]";
delfile($F);
$update = "delete from $dbtable where id='$I'";
$result = mysql_query ($update);
}
// NORMAL LISTING
if (!isset($upload)){
echo "<CENTER>";
echo "<TABLE width='600' CELLPADDING = '3' CELLSPACING='0' BORDER='0'>";
echo "<tr><TD bgcolor='#99cccc' colspan='5'><B>FORMS</B><td></tr>";
echo "<tr><TD bgcolor='#cccccc' ><B>ID</B></td><TD bgcolor='#cccccc' ><B>DESCRIPTION</B></td><TD bgcolor='#cccccc' ><B>TYPE</B></td><TD bgcolor='#cccccc' ><B>VIEW</B></td><TD bgcolor='#cccccc' ><B>DELETE</B></td></tr>";
$result3=mysql("$db","SELECT * from $dbtable");
while($value = mysql_fetch_row($result3))
{
$filename = $value[2];
list ($filepart, $fileext) = split ('[/.-]', $filename);
echo "<tr><TD valign='top' ><B>$value[0]</B></td><TD valign='top' ><B>$value[1]</B><BR><font size='1'>URL: $url/$directory/$value[2] </font></B></td><td valign='top'><b>$fileext</b></td><TD valign='top'><B><a href='$url/$directory/$value[2]'>VIEW</a></B></td><TD valign='top' ><B><a href='$PHP_SELF?I=$value[0]&D=Y'>DELETE</a></B></td></tr>";
}
echo "</table>";
// Line Division
echo "<P><hr size='1' width='600'></P>";
// START OF UPLOAD FORM
echo "
<FORM ENCTYPE='multipart/form-data' ACTION='$PHP_SELF' METHOD=POST>
<INPUT TYPE='hidden' name='MAX_FILE_SIZE' value='$maxsize'>
<INPUT TYPE='hidden' name='orderby' value='$orderby'>
<INPUT TYPE='hidden' name='item_id' value='$item_id'>
<INPUT TYPE='hidden' name='upload' value='Y'>
<TABLE width='600' CELLPADDING = '3' CELLSPACING='0' BORDER='0'>
<tr><TD bgcolor='#99cccc' colspan='2'>ADD FORM TO SITE<td></tr>
<tr>
<td>DESCRIPTION OF FILE:</td><td><INPUT NAME='description' TYPE='text' size='30'></td>
</tr>
<tr>
<td>FILE TO UPLOAD:</td><td><INPUT NAME='userfile' TYPE='file' size='30'></td>
</tr>
<tr>
<td colspan='2'><INPUT TYPE='submit' VALUE='Send File'></td>
</tr>
</FORM>
</table>";
} else {
if (file_exists($userfile)){
$file_size = filesize($userfile);
if ($file_size >= $maxsize) {
echo "<center>Thise File is too large.";
exit();
}
$goodtype = "N";
if ($userfile_type == "image/pjpeg") {
$ext ="jpg";
$goodtype = "Y";
}
if ($userfile_type == "image/gif") {
$ext ="gif";
$goodtype = "Y";
}
if ($userfile_type == "application/pdf") {
$ext ="pdf";
$goodtype = "Y";
}
if ($userfile_type == "application/msword") {
$ext ="doc";
$goodtype = "Y";
}
if ($goodtype == "Y") {
$this_date = date("Ymdhis");
$this_name = $this_date.".".$ext;
$insert = "insert into $dbtable (description,filename) values ('". addslashes($description) ."','$this_name')";
$result = mysql_query ($insert);
$items_id=mysql_insert_id();
echo "<CENTER><P>File has been uploaded!";
$thisfile = fread(fopen($userfile, "r"), filesize($userfile));
$new_file = "$rootdir/$directory/$this_name";
$filewrite = fwrite(fopen($new_file, "w"), $thisfile, filesize($userfile));
$this_info = "$url/$directory/$this_name";
echo "<P><a href='$this_info' target='_BLANK'>VIEW HERE</a></a>";
} else {
echo "$userfile_type is an unknown file type!<P> Sorry, but we only accept pdfs,docs,gifs and jpg file format!";
}
echo "<P><A href='$PHP_SELF'>ADD ANOTHER FORM</a>";
}
}
?>