saud_iqbal
05-26-2005, 06:10 PM
I need your help. Can you help me in adding the option of uploading and displaying the picture. I want that the user can upload his photo and the photo is displayed below his message. Is it possible with text database.
Any help.
The code is
<?
$gbfile='gb.txt';
$separator= '^';
//====================================
//This function will add one line to
//the end of file
//====================================
function add($str){
global $gbfile;
$tmp = trim($str);
$fp=fopen($gbfile,'a+');
flock($fp, LOCK_EX);
fwrite($fp, $tmp. "\n");
flock($fp, LOCK_UN);
fclose($fp);
}
//====================================
//Function below gets specified number
//of lines and returns an array
//====================================
function get($start, $end){
global $gbfile;
$records=array();
$filename="gb.txt";
$fp=fopen($gbfile,'r');
flock($fp, LOCK_SH);
$i=1;
$tmp=TRUE;
while($i<$start && !feof($fp)) {
$tmp=fgets($fp);
$i++;
}
while($i<=$end && !feof($fp)) {
$tmp=trim(fgets($fp));
if ($tmp) { array_push($records, $tmp); }
$i++;
}
flock($fp, LOCK_UN);
fclose($fp);
return($records);
}
//=============================================
//Start of the script
//=============================================
//If the method is post then add new message
//to the guestbook file
if ($REQUEST_METHOD=='POST' && $_POST['text']) {
$msg = str_replace($separator, '', htmlspecialchars($_POST['text']));
$author = str_replace($separator, '', htmlspecialchars($_POST['author']));
$email = str_replace($separator, '', htmlspecialchars($_POST['email']));
$homepage = str_replace($separator, '', htmlspecialchars($_POST['homepage']));
$tmp = implode($separator, array($msg, $author, $email, $homepage));
add($tmp);
}
//Listing part
$start=$_GET['start'];
$end=$_GET['end'];
if (!$end || $start<=0) { $start=1; }
if (!$end) { $end=10; }
if ($end<$start) { $end=$start+1; }
$show=$end - $start;
//Get records from file into array
$records = get($start, $end);
//For each record get each field
foreach ($records as $rec) {
$tmp = explode($separator, $rec);
$msg = $tmp[0];
$author = $tmp[1];
$email = $tmp[2];
$homepage = $tmp[3];
//=================================
//Outputting
?>
<HR>
Author: <?=$author?><br>
Email: <?=$email?><br>
Homepage: <?=$homepage?><br>
Text: <?=$msg?><br><br>
<?
}
//Pagination
if ($start>$show) {
$start-=$show;
$end-=$show;
print "<a href=gb.php?start=$start&end=$end>Prev $show</a> ";
if (count($records)!=0) {
$start+=$show*2;
$end+=$show*2;
print "<a href=gb.php?start=$start&end=$end>Next $show</a>";
}
else {
print "No more records found !";
}
}
else {
$start+=$show;
$end+=$show;
print "<a href=gb.php?start=$start&end=$end>Next $show</a> ";
}
?>
Any help.
The code is
<?
$gbfile='gb.txt';
$separator= '^';
//====================================
//This function will add one line to
//the end of file
//====================================
function add($str){
global $gbfile;
$tmp = trim($str);
$fp=fopen($gbfile,'a+');
flock($fp, LOCK_EX);
fwrite($fp, $tmp. "\n");
flock($fp, LOCK_UN);
fclose($fp);
}
//====================================
//Function below gets specified number
//of lines and returns an array
//====================================
function get($start, $end){
global $gbfile;
$records=array();
$filename="gb.txt";
$fp=fopen($gbfile,'r');
flock($fp, LOCK_SH);
$i=1;
$tmp=TRUE;
while($i<$start && !feof($fp)) {
$tmp=fgets($fp);
$i++;
}
while($i<=$end && !feof($fp)) {
$tmp=trim(fgets($fp));
if ($tmp) { array_push($records, $tmp); }
$i++;
}
flock($fp, LOCK_UN);
fclose($fp);
return($records);
}
//=============================================
//Start of the script
//=============================================
//If the method is post then add new message
//to the guestbook file
if ($REQUEST_METHOD=='POST' && $_POST['text']) {
$msg = str_replace($separator, '', htmlspecialchars($_POST['text']));
$author = str_replace($separator, '', htmlspecialchars($_POST['author']));
$email = str_replace($separator, '', htmlspecialchars($_POST['email']));
$homepage = str_replace($separator, '', htmlspecialchars($_POST['homepage']));
$tmp = implode($separator, array($msg, $author, $email, $homepage));
add($tmp);
}
//Listing part
$start=$_GET['start'];
$end=$_GET['end'];
if (!$end || $start<=0) { $start=1; }
if (!$end) { $end=10; }
if ($end<$start) { $end=$start+1; }
$show=$end - $start;
//Get records from file into array
$records = get($start, $end);
//For each record get each field
foreach ($records as $rec) {
$tmp = explode($separator, $rec);
$msg = $tmp[0];
$author = $tmp[1];
$email = $tmp[2];
$homepage = $tmp[3];
//=================================
//Outputting
?>
<HR>
Author: <?=$author?><br>
Email: <?=$email?><br>
Homepage: <?=$homepage?><br>
Text: <?=$msg?><br><br>
<?
}
//Pagination
if ($start>$show) {
$start-=$show;
$end-=$show;
print "<a href=gb.php?start=$start&end=$end>Prev $show</a> ";
if (count($records)!=0) {
$start+=$show*2;
$end+=$show*2;
print "<a href=gb.php?start=$start&end=$end>Next $show</a>";
}
else {
print "No more records found !";
}
}
else {
$start+=$show;
$end+=$show;
print "<a href=gb.php?start=$start&end=$end>Next $show</a> ";
}
?>