the folder upload form goes into the chat template around line 122 of chat.html.tpl.php
in the data folder I placed a folder uploads which holds the uploads
//start upload form
- Code: Select all
<div id="upload">
<form enctype="multipart/form-data" action="./uploader.php" method="POST">
<input name="uploadedfile" type="file" /><br>
<div id="uploadbutton">
<input type="submit" value="Upload File" />
</div>
</form>
</div>
//end upload form
this calls up uploader.php which does the work,
//uploader.php
- Code: Select all
<?php
header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache'); // For HTTP/1.0 compability
require_once "src/phpfreechat.class.php";
ini_set("display_errors", 0);
// Where the file is going to be placed
$target_path = "./data/uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path));
?>
<html>
<head>
<script type="text/javascript">
<!--
function delayer(){
document.location = './nchat.php'; // change this to your chat index
}
//-->
<!--
function silentErrorHandler() {return true;}
window.onerror=silentErrorHandler;
//-->
</script>
</head>
<body onload=" setTimeout('delayer()', 500);">
</body>
</html>
end uploader.php//
style.css.php controls where this is on the page , around lines 466 and below, note some are not hooked in
- Code: Select all
div#upload {
margin: 0; padding: 0;
position: absolute;
right: 270;
top: 0;
background-color: #fff;
border: #cccccc solid 1px;
color: 000;
font-family: verdana;
}
div#uploaded {
margin: 0; padding: 0px;
}
div#uploadbutton {
margin: 0; padding: 0;
position: absolute;
right: 40;
top: 25;
}
div#uploadresults {
margin: 0; padding: 0;
position: absolute;
z-index: 100;
right: 0;
top: 0;
font-size: 14px;
height: 1.9em;
cursor: pointer;
}
this is an iframe that pulls in an ajax seamless refresh script "refresh.php" that pulls in the file viewer "viewfiles.php"
- Code: Select all
<div id="uploadresults">
<iframe src="./refresh.php" class="i_frame" id="i_frame" style="width: 265px; height: 95px;" scrolling="auto" frameborder="0" style="overflow-y:scroll;"></iframe>
</div>
//start refresh.php
- Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript">
<!--
var vUri = 'viewfiles.php'
var vRequest;
function getRequest()
{
vRequest = null;
if (window.XMLHttpRequest)
{
vRequest = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
try
{
vRequest = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (err)
{
try
{
vRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (err)
{
return (false);
}
}
}
vRenew = new Date();
vTest = /?/;
vNewUri = vUri + (vTest.test(vUri)?'&':'?') + 'renew=' + vRenew.getTime();
vRequest.onreadystatechange = catchChange;
vRequest.open('GET', vNewUri, true);
vRequest.send(null);
}
function catchChange()
{
if (vRequest.readyState == 4 && vRequest.status == 200)
{
document.getElementById('i_reload').innerHTML = vRequest.responseText;
setTimeout('getRequest()', 5000);
}
}
getRequest();
//-->
</script>
</head>
<body>
<div class="i_frame" id="i_reload"></div>
</body>
</html>
//end refresh.php
//start viewfiles.php
- Code: Select all
require_once "src/phpfreechat.class.php";
$target_path = "./data/uploads/";
filesInDir($target_path);
function filesInDir($tdir)
{
$dirs = scandir($tdir);
foreach($dirs as $file)
{
if (($file == '.')||($file == '..'))
{
}
elseif (is_dir($tdir.'/'.$file))
{
filesInDir($tdir.'/'.$file);
}
else
{
echo "<img src="images/download.gif" ><a style="text-align:right;color: steelblue;text-decoration: none;font-style: italic;font-weight:bold;font-size:14px" href="$tdir/$file" target="_blank"> $file </a><br />";
}
}
}
?>
//end viewfiles.php
note: the images will be missing, sorry