TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 11-10-2008, 01:41 AM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application self submited form problem, sorting, cleaning and array...

Good day to you all,

Here I am again with another question regarding a listing and creating file.
This time I would like to 4 things;

- Clean my code, I clean the list and display only the txt file, but I do it 2 time same for where I display it, I'm sure there is a better way..?

- Sort last added message on top.

- When I add text, the page does not refresh and show what I just enter, I have to add another text to see it, on and on...

- Could I get the result of the listing into an array ?


Here is my code:

PHP Code:

<?php

//Receive post 
if(isset($_POST['Submit'])){

// list only txt file 
$extensions = array('txt');
$thelist "";
 if (
$handle opendir('.')) {
   while (
false !== ($file readdir($handle)))
      {
          
$ext strtolower(end(explode('.'$file)));
       
          if (
in_array($ext$extensions) AND $file != "." AND $file != "..")
      {
              
$thelist .= '<table border=\"1\" align=\"center\"><tr><td width=\"500\"><a href="'.$file.'">'.$file.'</a></td></tr>';
              
$contents file($file);
              
$string implode($contents);
              
$thelist .= '<tr><td>'.$string.'</td></tr></table><br/>';
            
          }
       }
  
closedir($handle);
  }


//Show the form
echo "<form action=\"\" method=\"post\">";
echo 
"<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
echo 
"</textarea>";
echo 
"<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>"
;

//Show the list
echo "<P>List of files:</p>";
echo 
"<P>".$thelist."</p>";





// Declare Variables
$text $_POST['update'];
$your_data $text;



// Open the file and erase the contents if any
$fp fopen(date('Y')."-".date('m')."-".date('d')."-".date('G')."-".date('i')."-".date('s').".txt""w");

// Write the data to the file
fwrite($fp$your_data);

// Close the file
fclose($fp);

// Confirm saved !
echo "File updated.<br />"




//else, if you are not receiving a post...
}else{


// list only txt file 
$extensions = array('txt''ou');
$thelist "";
 if (
$handle opendir('.')) {
   while (
false !== ($file readdir($handle)))
      {
          
$ext strtolower(end(explode('.'$file)));
       
          if (
in_array($ext$extensions) AND $file != "." AND $file != "..")
      {
              
$thelist .= '<table border=\"1\" align=\"center\"><tr><td width=\"500\"><a href="'.$file.'">'.$file.'</a></td></tr>';
              
$contents file($file);
              
$string implode($contents);
              
$thelist .= '<tr><td>'.$string.'</td></tr></table><br/>';
            
          }
       }
  
closedir($handle);
  }


//Show the form
echo "<form action=\"\" method=\"post\">";
echo 
"<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
echo 
"</textarea>";
echo 
"<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>"
;

//Show the list
echo "<P>List of files:</p>";
echo 
"<P>".$thelist."</p>";



}
?>

Thanks for your time !
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:03 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design