Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $datab = fopen('database.txt', "r+");
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>Facebook v0.1</title>
- <style type="text/css">
- #bod{
- margin:0 auto;
- width:800px;
- border:solid 2px black;
- }
- </style>
- </head>
- <body>
- <div id="bod">
- <?php
- $fname = $_REQUEST['fname'];
- $lname = $_REQUEST['lname'];
- $comment = $_REQUEST['comment'];
- $datab = $_REQUEST['datab'];
- $gfile = $_REQUEST['gfile'];
- print <<<form
- <table border="2" style="margin:0 auto;">
- <td>
- <form method="post" action="">
- First Name :
- <input type ="text"
- name="fname"
- value="">
- <br>
- Last Name :
- <input type ="text"
- name="lname"
- value="">
- <br>
- Comment :
- <input type ="text"
- name="comment"
- value="">
- <br>
- <input type ="submit" value="Submit">
- </form>
- </td>
- </table>
- form;
- if((!empty($fname)) && (!empty($lname)) && (!empty($comment))){
- $form = <<<come
- <table border='2' width='300px' style="margin:0 auto;">
- <tr>
- <td>
- <span style="color:blue; font-weight:bold;">
- $fname $lname :
- </span>
- $comment
- </td>
- </tr>
- </table>
- come;
- $datab = fopen('database.txt', "r+");
- fputs($datab, $form);
- fclose($datab);
- }else if((empty($fname)) && (empty($lname)) && (empty($comment))){
- print" please input data";
- } // end table
- $datab = fopen('database.txt', "r");
- while (!feof($datab)){
- $gfile = fgets($datab);
- print "$gfile";
- }// end of while
- ?>
- </div>
- </body>
- </html>
- <?php
- $file_data = "Stuff you want to addn";
- $file_data .= file_get_contents('database.txt');
- file_put_contents('database.txt', $file_data);
- ?>
- function prepend($string, $orig_filename) {
- $context = stream_context_create();
- $orig_file = fopen($orig_filename, 'r', 1, $context);
- $temp_filename = tempnam(sys_get_temp_dir(), 'php_prepend_');
- file_put_contents($temp_filename, $string);
- file_put_contents($temp_filename, $orig_file, FILE_APPEND);
- fclose($orig_file);
- unlink($orig_filename);
- rename($temp_filename, $orig_filename);
- }
- $myFile = "test.csv";<br>
- $context = stream_context_create();<br>
- $fp = fopen($myFile, 'r', 1, $context);<br>
- $tmpname = md5("kumar");<br>
- //this will append text at the beginning of the file<br><br>
- file_put_contents($tmpname, "kumar");<br>
- file_put_contents($tmpname, $fp, FILE_APPEND);<br>
- fclose($fp);<br>
- unlink($myFile);<br>
- rename($tmpname, $myFile);<br><br>
- //this will append text at the end of the file<br>
- file_put_contents($myFile, "ajay", FILE_APPEND);
- $data = "new stuff to insert at the beggining of the file";
- $buffer_size = 10000;
- $f = fopen("database.txt", "r+");
- $old_data_size = strlen($data);
- $old_data = fread($f, $old_data_size);
- while($old_data_size > 0) {
- fseek($f, SEEK_CUR, -$old_data_size);
- fwrite($f, $data);
- $data = $old_data;
- $old_data = fread($f, $buffer_size);
- $old_data_size = strlen($data);
- }
- fclose($f);
- $data = "new stuff to insert at the beggining of the file";
- $buffer_size = 10000;
- $f = fopen("database.txt", "r+");
- $old_data_size = strlen($data);
- $old_data = fread($f, $old_data_size);
- while($old_data_size > 0) {
- fseek($f, SEEK_CUR, -$old_data_size);
- fwrite($f, $data);
- $data = $old_data;
- $old_data = fread($f, $buffer_size);
- $old_data_size = strlen($data);
- }
- fclose($f);
- $file_data = file_get_contents('database.txt')
- $fp = fopen('database.txt', 'a');
- fseek($fp,0);
- fwrite($fp, 'new content');
- fwrite($fp, $file_data);
- fclose($fp);
- $fp_source = fopen('database.txt', 'r');
- $fp_dest = fopen('database_temp.txt', 'w'); // better to generate a real temp filename
- fwrite($fp_dest, 'new content');
- while (!feof($fp_source)) {
- $contents .= fread($fp_source, 8192);
- fwrite($fp_dest, $contents);
- }
- fclose($fp_source);
- fclose($fp_dest);
- unlink('database.txt');
- rename('database_temp.txt','database.txt');
- $handler = fopen('1.txt', 'w+');//1
- rewind($handler);//3
- $prepend = "I would like to add this text to the beginning of this file";
- $chunkLength = strlen($prepend);//2
- $i = 0;
- do{
- $readData = fread($handler, $chunkLength);//4
- fseek($handler, $i * $chunkLength);//5
- fwrite($handler, $prepend);//6
- $prepend = $readData;//7
- $i++;
- }while ($readData);//8
- fclose($handler);
- $fh = fopen($filename, 'a') or die("can't open file");
- fwrite($fh, $fileNewContent);
- fclose($fh);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement