File Re-writing And Moving The File Pointer
i have a text file that looks like this:
<bt>600</bt>
<iregno>123123</iregno>
<users>
<un>2</un>
<u1>
<n>Username</n>
<ema>username@domain.com<ema>
<s>password</s>
<t>user type</t>
<p>profile name</p>
<cat>000000000000000000000000000000000</cat>
</u1>
and so on
</users>
Now i run this big user edit function where im reading in their details and displaying them in forms and so on. They then edit the form fields and i read them back in using $POST. That's the easy part. What i then want to do is re-write a section of my text file.
I have a variable that tells me what user i need to re-write the details for, i also have all the new details that i need to replace the old ones with. So, in logical terms, what i need to do is move my file pointer to that section of the file:
read in $userToEdit variable -> output of variable is <u1> -> move file pointer to next line (<n>username</n>) and let me rewrite the next 6 lines therefore leaving the pointer at </u1> I hope that makes sense. Just basically want to rewrite the text that is there, not append/add.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Moving To New Line When Writing Out A File
What I'm trying to do is insert a new category into a array then write the array out to a file. This works, however, the text file uses carrage returns to seperate the items of the array. For example: cat1 cat2 cat3 What happens when I write the file is: cat1 newCatcat2 cat3 (assuming that newCat is sorted between 1 and 2) What I want is to have the next item in the array pushed to the next line, but I have not been able to do this. here's my code:
File Pointer At Beginning Of File
The following is taken directly from the PHP quick ref section under fopen. 'r' - Open for reading only; place the file pointer at the beginning of the file. 'r+' - Open for reading and writing; place the file pointer at the beginning of the file. 'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. 'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. None of these do what I want though one of them say they will. I need to write input from a form to the beginning of a text file. But when I use $myFile = fopen("file.txt","r+"); it writes to the beginning of the file. But when I execute the script again it writes OVER what was previously there. I need it to INSERT the input from the form. I'm fairly new to PHP so if I've not included some valuable information let me know.
Moving Uploaded File
I am trying to make a simple file upload page. It will not move the file properly. It only spits out the error message. Here's the code:
Writing To A File
The script below writes to a file and sends back confirmation that all is well. That is working correctly. The problem I am having is when I view the blank data.txt file that I uploaded to the server (and yes, I have put the file permissions to rw-rw-rw) its still blank!!!!!!! despite my little script stating that all is well. The same script works perfectly well on the totalise server. If the answer is to run the script as cgi I am too sure how to carry out the 7 different suggestions advised at the FAQ. I am OK at saving the script with a .pl or .cgi extsion instead of .php but how do I incorporate the extra line of code(#!/usr/bin/perl?) do I use it everytime I open php in the script or just once at the start. What exactly is the base path and how do I check to see if it is set correctly. The script in question is: (basically it handles the data(an URL and a description) coming from a html form and writes these to a file(data.txt) <?php function WriteToFile ($URL, $Description) { /* Function WriteToFile takes two arguments--URL and Description--which will be written to an external file. */ $TheFile = "data.txt"; if(is_writeable($TheFile)){ $Open = fopen ($TheFile, "a"); if ($Open) { fwrite ($Open, "$URL $Description "); fclose ($Open); $Worked = TRUE; } } else { $Worked = FALSE; } return $Worked; } // End of WriteToFile Function. ?> <HTML> <HEAD> <TITLE>Using Files</TITLE> </HEAD> <BODY> <?php /* This page receives and handles the data generated by "form.html". */ $Pattern = "(http://)?([^[:space:]]+)([[:alnum:].,_?/&=-])"; if (eregi($Pattern, $Array["URL"])) { $Replace = "<a href="http://23" target="_new">23</a>"; $Array["URL"] = eregi_replace($Pattern, $Replace, $Array["URL"]); $CallFunction = WriteToFile ($Array["URL"], $Array["Description"]); if ($CallFunction) { print ("Your submission--$Array[URL]--has been received!<BR> "); } else { print ("Your submission was not processed due to a system error!<BR> "); } } else { print ("Please enter a valid Web address! "); } ?> </BODY> </HTML>
Writing To A File
How would I go about reading and writing from a file? I would like to make a Web GUI for my sendamail virtualhosts.
Writing To A File
I am opening a file copying the contents and trying to write the contents into a newfile in a different directory. but its not working. <?php if ($handle = opendir('/home/jarntz/cdstuff/files')) { //echo "Directory handle: $handle"; echo "Files:"; while (false !== ($file = readdir($handle))) { echo "$file<br>"; $namelen = strrpos ($file, "."); $name = substr($file, 0, $namelen); print "$name<br>"; $filename = "/home/jarntz/cdstuff/files/$file"; $fd = fopen ($filename, "r"); $contents = fread ($fd, filesize ($filename)); fclose ($fd); $ncontents = nl2br ($contents); $scontents = "Test<br>" . $ncontents; print "$scontents<br><br>"; if($name){ $storefile = "/home/jarntz/cdstuff/html/" . $name . ".html"; print "$storefile<br>"; $myfile = fopen ($storefile, "w"); $fp = fwrite($myfile, $scontents); fclose($myfile); } } closedir($handle); } ?>
PHP Writing To A File Help
I am trying to create a script that will take the MYSQl DB details that have been sent from a form and store it in a file for usage at a later stage. Am I doing this correctly:
Writing To A File
How can I write to a file on a certan line? Like I have a file with 10 rows, I want to change row number 5 without changing the other rows.
Writing To A File
I have the following code that displays email addresses on the screen and saves them to a file. The problem is, depending on what flag I put for $fp, it either doesn't write or if it does it doesn't overwrite what's there, just appends it. What can I do about this? Also, on the screen, it displays each record followed by a <br>. In the file, it just displays all the email addresses in a big block. PHP Code:
Writing To A File
im having problems writing to a file - What i want to do is to is write html code to another php file. PHP Code:
Writing Csv Or Txt File
I am trying to create a method of exporting a csv or plain text file from a mysql database, so that users can save this file to disk for use in Excel or other popular spreadsheet & database applications. I have a query which selects the records, and I can format it easily enough using HTML table and related tags... Does anyone know a good way to format the results of the query so users can save this file as txt/csv file?
Writing To File With Php
Currently working my way through 'PHP and MySQL Web Development' by Luke Welling and Laura Thomson and am having difficulty writing to file in one of the examples. It throws up the following error: Warning: fopen(c:inetpubwwwroot/../orders/orders.txt) [function.fopen]: failed to open stream: No such file or directory in C:InetpubwwwrootLearn PHP and MYSQLLuke Wellingprocessorder.php on line 64 Code:
Writing To A Txt File
i have to save some form data to a .txt file, using one of the form variables ( #studentid ) as the file name, e.g. if the #studentid submitted was 123 then the file would save as 123.txt.
Writing A Txt File By A Form
Hi, I want to create a txt file containing the next content: min=5 &max=8 &x=70 These are variables wich are needed by a Flash swf file. (The Flash swf file displays the weather forecast.) I want to make a form which submit 3 values to a txt file called update.txt How can I do this with php? I want to submit the 3 values with a form. Is it possible to do this more than once so the variables (or the whole textfile) can be updated?
Writing To A File...and Using A Password
does anyone know of a script that will enable me to write to a file i specify, but require a password to use the script at all? a toutorial would also be nice.
Writing A Node To An XML File
I want to write a node or nodes to an existing xml document. I don't need to create a new document, thanks but no thanks. Judging from various posted topics I've seen. It appears the php DOM for XML isn't quite there yet and has a lot of bugs. Not only that it takes a few months before web hosters update versions of php. I tried the pear classes, but they're so poorly documented, there's no example, there's nobody you can contact at Pear for hlep. If you ask for help on forums, you get no reply's so obviously not many ppl are using these classes. I wonder..... if there's a push from say mySQL to stall or slow down PHP's functionality for XML? Any ideas on how to write a node or nodes into an existing XML file..... without a bunch a array manipulation?
Writing To A Text File
i have a text file with the number 250 in it and nothing else. i have a variable which is worth a 300. How can i add this value to the one in the file so that the value of the file has changed to 550?
Writing To The .htpasswd File?
is there a way to write the username/password to the .htpasswd file using a form in php, while also inserting into a mysql db...(i've already got the db part down)
Writing PHP To File W/fwrite()?
I'm trying to write this code to a index.php file when i generate directories on my site, like: PHP Code: fwrite($handle, " <? $file = file('http://www.somesite.com/?page=sublist&cat=$row[cid]'); foreach($file as $line){ echo $line; } ?> "); fclose($handle); which seems to kind of work, but it takes some of the code out and leaves me with this inside the index.php file: <? = file('http://www.sometime.com/?page=sublist&cat=1'); foreach( as ){ echo ; } ?> seems to remove anything with a $ in front of it, any ideas on how to get around this?
File Writing Issue
I am writing a file using PHP and all is great thus far: [code....] However I want to add the facility for the file to be written into a sub directory that may or may not exist - if the folder exists then it works fine - if it doesn't then it throws an error. Without having to write a section of code to check if the folder exists, is there a way of forcing PHP to build any required folders for me?
Writing To File Problems
everytime I write to a file, a little black square character is added to the end of the file. I have no idea why this is happening. I'm testing this on my Apache server on Windows XP Home Edition.
PHP Instances Writing To The Same File?
I read in Programming PHP (O'Reilly) that flock() "cannot prevent two PHP scripts running in the same web server process from accessing a file at the same time". In my case a single PHP script appends text strings to an existing text file. Several clients may trigger the same script on the same web page and thus more than one PHP instance might try to open and append text to the same file at the same time. I would assume that using flock() _does_ in fact prevent simultaneous access in this case. Am I correct?
Writing To A Local File
We have a PHP/MySQL database application. A user would like to be able to run a routine to read selected data from the database and export a flat file to their local C: drive. After reviewing the documentation and posts, it is not clear how to do this, or even if it is allowed by the browser. If someone could point us in the right direction, we would greatly appreciate it. The application is hosted on a Linux server. The users are required to use Internet Explorer running on Windows 2000 or XP (we also use VBScript).
Writing A Session Value To File
windows xp, apache, php and my sql and dreamweaver mx I have the code below. And it does'nt work! Basically the code below is the workings behind the scene that inserts a record to a table and it gets most of it's value from a form. There's alot more to the code such as the bindings to text boxes etc but I don't think I need to show you that, just the basics. Most of the values come from text box bindings but one of them is a hidden value $custid Basically a user has logged in prior to the insert page and then I set a session with their userid. When they then want to insert a record I don't insert the userid but the customer id ($custid) and I have a bit of code that supposedly grabs the custid from a customers table doing a join on the userid. The insert code below works but it writes back nothing to the custid field in the table. The code below is a combination of dreamweaver mx generated code and my hand code. <? session_start(); if ($_SESSION[loggedin] != "yes") { header("Location: http://127.0.0.1/custlogin.php"); exit; } require_once('Connections/local.php'); // this bit gets the custid from the cutomers table and assigns it to the variable $thecustid $thecustid = "SELECT custid FROM customers WHERE userid='" . $_SESSION['MM_Username'] . "'"; // dreamweaver created all this function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; }
Writing To The Excel File
What would be the best way to write to an excel file from PHP and also append the same excel file. Say on the click of a form I want the information to be appended to the excel file.
Looping And Writing To A File
I have a function here that will (with some other functions not shown here) display some results from a database. Here is the code: function display_song_list($fd, $e) { global $sys_install_base; global $sys_relative_uploaddir; echo ("<songs> "); foreach ($e as $error) { echo ("$error "); } $c = pg_numrows($fd['result']); for ($i = 0; $i < $c; $i++) { $r = pg_fetch_assoc($fd['result'], $i); echo ("<song title="{$r['song_title']}" artist="{$r['artist']}" path="{$sys_install_base}{$sys_relative_uploaddir}{$r['audio_file']}"/> "); } echo ("</songs>"); }
UTF-8 File Reading And Writing For PHP
I'm creating a page that: - accepts user input in whatever language - saves that input to a file - reads the file and displays the original input The following code successfully writes the user input to a file (when I open the file, it's in the correct font), but I can't get PHP to read the file and display the correct characters. HTML --------------- Form <FORM name=saveform method=post action="wiki.php"> File: <TEXTAREA name=thetext rows=20 cols=30></TEXTAREA> </TEXTAREA> <INPUT type=submit> <INPUT type=hidden name=action value="save"> </FORM> PHP --------------- Sticks the data in a file $message = $_REQUEST['thetext']; echo $message; // This displays the correct stuff $filename = "tmp/tmp.txt"; $fr = fopen($filename, "wb+"); // adding header fwrite($fr, pack("CCC",0xef,0xbb,0xbf)); fputs($fr, $message); fclose($fr); PHP --------------- Read the data from the file $thefile = file($filename); array_shift($thefile); //To get rid of the BOM $ret = ""; foreach ($thefile as $i => $line) { $line = rtrim(utf8_decode($line)); $ret .= $line; } echo $ret; // This _doesn't_ display the correct stuff
Writing Data To A .txt File
im making a site which allows the user to type in their e-mail address and send it to my "emails.txt" file. Its not really working though... It seems like everything is right but it doesnt add it: Heres part of the code:
Writing To File From A Form
How can i crate a form, with a button so when it is clicked, letters from a form are writen to a file... Like this: So i write something to it, click Submit and the txt is saved to a name.txt file on a server...
Writing To .txt File -simple, Right?
I've got this piece of PHP code on one site (server) and it works fine with the other 2 files. I've copied the exact same files to another server and it doesn't work. everything in all the files are relative paths and I don't understand why it's not working. I've checked with the hosting provider and they tell me that PHP is enabled on the second account, but it's still not working even with exact duplicate files. I'm wondering if it's because the second server is running on PHP5. I'm not sure what the first server is running, but could that be causing the problem? Code:
Writing To A Text File On Another Server
I've a form on one server, which posts its contents to a PHP script that tries to write one of the fields to a text file on another server. When testing this, when I try to write to a text file on the SAME server, everything's fine, it writes successfully. However, it doesn't work when trying to write to a remote file, and doesn't even throw up any errors. Here's the code: $fp = fopen( "http://server.server.com/server/textfile.txt", "a" ) or die ("Couldn't open"); flock( $fp, 2 ); // exclusive lock fwrite( $fp, "$email " ) or die ("Couldn't write"); flock( $fp, 1 ); // release the lock fclose( $fp ); Does anyone know why it's not working?!? Please help me!!!
Writing To File On Remote Server
Is it possible to open and write to a file on a remote server by using the command fopen("http://www.myserver.com/myfolder/file.jpg", "w") ? If I try this, fopen does not return a file pointer (Even if /myfolder is "wide open", chmod 777).
Writing To A File And Not Having To Do An Fputs For Each Line
I'm trying to output HTML files with php. I have read that in order to do this, I have to preface each line with something likes; fputs($filepointer, "the line that I want"); I want it to just spit out text that is already in paragraphs and junk with all of the HTML Code. Is there a way to do it the same way I predeclare printing with print <<<ENDTAG yadda ENDTAG; How can I do something like that only I am printing to create a file without fputs for each $#!! line?
Writing To A Specific Place In A File
I have a text file. I would like to write a line of data as the first line and then another as the last line. What is the easiest way to do this using php 4?
Writing Records To Text File
I have the following code which displays some some formatted text in my browser. The problem is I need to create a text file and write the records from this array into it. Does anyone know how to acheive this...
Question Re Writing To A Text File
I am attempting to code a small script to process the fields from a form and write it to a text file using the semi-colon as the delimiter. So far I am successful in doing that using the following: $incoming_fields = array_keys($_POST); $incoming_values = array_values($_POST); for ($i = 0; $i < count($incoming_fields); $i++) { $fp = fopen("formresults.txt", "a"); fwrite($fp,stripslashes("$incoming_values[$i];")); fclose($fp); } But what I am encountering difficulty in is putting a line break ( ) at the end of only the final entry so that the data from each form submission is on a separate line.
Writing To A File On A Remote Server Without FTP
I am new to PHP and have a small problem and wondered if anyone could help. We have three sign-up areas for our site, two are hosted on our server, a third on another site for very good reasons. I want a logfile of when people subscribe. The logfile is hosted on our server. Writing to the logfile is easy for the two scripts running on our server. My original plan for the remote site had simply been to open an FTP connection and write it that way, and that worked a treat - until I got the remote site to test it on their servers. They do not allow outbound FTP. This may be the world's stupidest question, but is there another way of passing the results of the sign up (which is just a date, an email address and to which list they have subscribed) to the logfile on our server without using FTP? Is there someway I could use $_POST for example?
Writing To Existing Text File
I am having some problems writing to a file that already exisits. I can create a new file and write to it, but when I try to write to that file later it fails. When a form is submitted the text from that form is to be written to a file. The user is then redirected to a page advising of the outcome of the submit. IE Success, data written, Failure (The file could not be opened) or Failure (The file could be opened, but not saved). Code:
Problem With Writing To A Text File.
I have the following script where I am querying a table and then want to write the results into a text file delimited by |+|+| and also has a return like after each row. But my script seems to be doing a after every field and not row. How can I change this so that it happens after every row and not field. PHP Code:
Writing Info To Text File
im writing some info to a text file im trying to make my script write people's ip and stuff PHP Code:
Writing To Multiple Lines In File.
I was wanting to make a list of text field data enetered everytime someone filled out the form. I tried using fwrite() but everytime someone submits on the form it overides the previous entry. I also tried fwrite($fh "$entry"); but it did the same thing. How can I do this?
Simultaneous Writing And Reading Of A File.
I would like to solve the following problem. On the server side I have a file with a sequence of natural numbers (1, 2, 3, 4, 5, ...., n). Each user, after some action, adds new number (n+1, where n is the last number in the file) to the end of file. To do this user has to open the file for reading, read the last number, perform corresponding manipulations with the extracted last number and add result to the end of the file (after opening it for adding). However, it can happens that during one user performs algebraic calculation with the last extracted number, some another user opens the file with numbers, performs the same algebraic manipulation, and adds result to the end of file. Afterwards, the first user finishes his calculation and adds the same number to the file. I would like to avoid this situation. My solution is to keep file opened during algebraic calculations. It is the sequence should be the following. Open file, read the last number, with the usage of the last number calculate next number, add this new calculated number to the end of the file, close the file. The first my question is whether one can do it. I mean can one open file for both reading and adding? If yes, how one need to do it? And the last question is whether it helps to solve my problem? I mean, is it thru that during file is opened by one user, another user cannot read and change this file?
Fwrite Stops Writing To File?
I am currently working on a simple obfuscation function which I apply on $filecontent (see below). What I am currently doing is loading the source file like: PHP Code:
|