TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Don't had to page ??? (http://www.talkphp.com/advanced-php-programming/3677-dont-had-page.html)

Peuplarchie 11-28-2008 09:33 PM

Don't had to page ???
 
Good day to you all,
the following pice of code is for opening a file, and write to it.
My problem is that the text is not copied in the file.

Here what it should do.
This script is in a page which contain a form that post the result to the page. (self-submit)
Receive the post $update
Create a file named, username-hour-minute-second.txt within today's folder.
Save the content of the post in the newly created file.


here is the code:
PHP Code:

if(isset($_POST['update']))
{

    
// Declare Variables
    
$text $_POST['update'];
    
$your_data $text;
    
$mname date("Y/m/d/")."/"$_SESSION['username']."--".date("G-i-s").".txt";
    
// Open the file and erase the contents if any
      
$fp fopen($mname"w"); 
    
// Write the data to the file
    
fwrite($fp$your_data);
    
// Close the file
    
fclose($fp);
    
// Confirm saved !
    
echo "Comment added !<br />".$your_data







Thanks !

Wildhoney 11-28-2008 10:50 PM

Here it is nice and simple. You don't necessarily need to use the fopen, fwrite and fclose functions as PHP5 packages those nicely into one function for us:

php Code:
$szData = 'TalkPHP.com';
$szFolder = sprintf('./%s/', 'Wildhoney');
$szFile = sprintf('%s.txt', date('Y-m-d'));

if (!is_dir($szFolder))
{
    mkdir($szFolder);
}

file_put_contents($szFolder . $szFile, $szData);

Peuplarchie 11-28-2008 11:41 PM

I'm using php 4

zxt3st 11-29-2008 03:11 AM

I recommend you to use PHP5. Upgrade your php folder to version 5. There are a lots of new things in php 5 that is nonetheless not present in php4.

Just take a look at the example above and you will notice a big difference :)


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

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0