How To Read A File, Edit And Replace That File With New Changes?
I am making a enhancement to our helpdesk product. So we are using JSON for saving the Language defaults. Now I am Using PHP as a server based language. Now here is the logic of the program. Whenever our product is installed then a parser will create a HTML file which will have all the defaults from the JSON file. Now when a user changes the language then the parser will again Run and make the required changes in the JSON file and again create the HTML file and Replace it in that folder. I am not able to find a good solution for this.
Can someone help me building it. I am not able to get how to Open a file, Read it, make the changes and Replace that file.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
PHP/IIS: File Read/Write OK, File Unlink Denied
I've got PHP running fine on IIS (OS: Server 2003, SP1; IIS: 6.0; PHP: 4.3.11). In PHP, the user uploads a file, which is then processed and the contents are inserted into a new file, created in PHP, onto the server. This bit works fine, the new file created by PHP is correctly stored. Later, once the user confirms the upload and PHP inserts the contents of the file into the DB, the code tries to remove the file created in PHP moments earlier, via the unlink() function. What I see on screen is the following: Permission denied I have made sure that the permissions for the Internet account that created (and is trying to delete) the file have full permissions over this particular folder and the files within it. But the user must have permission anyway, because they are able to create this file in the first place. I've looked at the permissions for the file in PHP, which read: 0666. So everthing *appears* ok to me; I can't see where the permission issue is coming from.
Trying To Edit A Txt File
Hi I am trying to edit a text file... the format of which is like #####abc.conf poll somethin proto pop3 via 127.9.02.1 user "me@me.com" pass "dell" is me.nutcase preconnect "abc abc abc abc" ## poll ak # proto pop3 via 11.11.22.33 user "ak@bk.com" pass "eatme" is nutter fetchall preconnect "abs -e -f -f /ss/ss/ " ## The way i am tryin to edit this file is .... <?php $file = "/som/thing/abc.conf" $dele = "poll ak"; $open = fopen($file, "r+w"); $read = fread($open, filesize($file)); $sep1 = explode($dele, $read); $sep2 = explode('##', $sep1[1]); $read = str_replace(array($dele, $sep2[0]), array("", " "), $read); fseek($open, 0); fwrite($open, $read); fclose($open); The result of what happens is it delete the tag from poll ak till the ## but also adds some text at file end like .... Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2Resource id #2defaults via 11.11.22.33 user "ak@bk.com" pass "eatme" is nutter fetchall preconnect "abs -e -f -f /ss/ss/ "
Php Edit Xml File
I have an xml file that looks roughly like this: <?xml version="1.0" encoding="ISO-8859-1" ?> <videos> <video url="new.flv" desc="Guitar Solo" /> </videos> what i want to be able to do is add more entries like "<video url="new.flv" desc="Guitar Solo" />". How can I get it to add the entry into the right place, so it doesnt show up after the </videos>?
Edit/replace?
How would I edit or replace a field of a row in my database?
Edit TXT File If Script Is Not There.
I want this script to instead of saying you're a guest, into deleting a line in a TXT file. Is this possible? Below is the script I'm using. if(stripos(file_get_contents('http://www.othersite.com/page.html'), '<script')!== false) echo('You're an affiliate.'); else echo('You're a guest.') also is it possible to "search" for a tag or something in the text code and delete it?
Edit Apache File On The Fly
I would like to know how to read my apache conf file and for each domain put them into form fields. also would it be easier to keep each virtual hosts in their own files and is this possible? PHP Code:
Remote File Edit
i want to edit my index.php by www i print file in 'textarea': <textarea cols="95%" rows="20" name="text"> <?php readfile("../index.php"); ?> </textarea> how can i save contents after editing it (editing in this textarea)?
Edit Lines In Txt File
i am trying to write data that i have stored in a session back to a member.txt, but i am unable to work out why it wont write. It displays the data i have stored in the session ok, but it wont do the next step! I have used a similiar script in another part of my web page which works, but this one won't. From my understanding it has something to do with if statement if($data[0] == $user_id), so i might be trying to compare the previouis data to the current data stored in the txt file properly....
Edit Text In A Txt File
here is the php code! i am trying to use to 'edit' hyperlink to edit txt in member.txt. Problem is that it reads the values ok into an array, however when i attempt and update new values into the file, i get no results. Does anybody know where i am going wrong???? <? session_start(); // Set updated content for user if(!isset($_POST[Submit])) { // read content from file and place into array, this is used to put initial content into form $fc=file("../username/member.txt"); $userid_no = $_GET['record_id']; $line = split("|",$fc[$userid_no]); $user_id = $line[0]; $password = $line[1]; $firstname = $line[2]; $lastname = $line[3]; $email = $line[4]; } else { if(isset($_GET['record_id'])) { // build record into string from post values $update = $_POST['user_id']; $update .= "|"; $update .= $_POST['password']; $update .= "|"; $update .= $_POST['lastname']; $update .= "|"; $update .= $_POST['firstname']; $update .= "|"; $update .= $_POST['email']; $update .= "|"; $update .= ""; $update .= "|"; $update .= "2";
Edit Text File
I am trying to find a specific line, which starts with a unique word, then delete that line in the .txt file then rewrite that line. Code:
Word File Edit
I am trying this code to edit word file, it works fine if the both strings are same lenght but not if both are of different length. <?PHP $tmp=file_get_contents("work.doc"); $tmp = str_replace ("sys" , "asd",$tmp); $tmp=file_put_contents("work2.doc" , $tmp); ?>
How To Edit A Line In A Text File
i have a text file (just testing php) which stores about 10 lines where each line represents a user request. how do i edit that line to allow the user to edit the $bookwanted ? the lines below shows my display info for the user. $file=file('logindata.txt'); foreach($file as $line){ list($bookwanted,,$user,$pass,$acct,$email,$amt,$date)=explode('|',$line); if (($username == $user) && ($password == $pass) ) { // display info for that particular user }
Read And Edit Xml With PHP
I'm trying to write some php that will read in some xml and then allow me to modify the tag and write back out to xml. In the following example, I want to read in 'text_for_paragraph_1', then allow it to be viewed, edited, and saved back to the xml... I have absolutely no clue even where to start...
PHP Flat File Database - How To Load And Edit Lines?
I am using a text file as a database, each field delimited by || I want to be able to print all lines to a page, then by selecting one (with, say, a radio button) it will load into the form at the bottom of the page, where I can edit the fields, and save back to the same line in the text file. I dont know how to use primary keys or anything with a text file database,
Dir Read / Write / Edit
I have some files in web server in a dir (e.g. /download/*.*) I don’t want any kind of database support. Objectives: - I want to upload files in that dir. - I want to see all files in that dir. - I want to delete/Edit the files. - I want to download the files. - When I click download the files, In case of Image files (or, any file types that the Brower can open) it open automatically open in to that window (But I want it to download only)..
Replace A File?
I have a file upload form and the file is moved and renamed based on the users id number. Example userId #150 = 150.jpg. How can I allow the user to upload, using the same form, but replace the existing file so it will still read 150.jpg but with a new image (replacing the old one). Code:
Replace The Last Line Of File
I have a text file and I want to replace the last, and only the last of the file with some other text I store in a variable.
Can't Replace Uploaded File
I have the following problem, I have a database (MySQL) in which I can store filenames, in my script I can select a file from my hard drive that will be uploaded and stored in a directory on the server. So far so good. Now when I want to replace the file by another one and use the same script it won't replace the file. Does anybody outthere know what the problem might be?? The following code is my part of the script that does the uploading: if ($img1_name != "") { copy("$img1", "/home/sitename/www/dbasepictures/$img1_name") or die ("Couldn't copy the file!"); } else { die("No input file specified"); }
Search And Replace In Text File
I have a text file with 30 or so lines. Each line has this format: sometext somevalue. They are separated by a single space. I want to search in the file for "sometext" and replace "somevalue" with a particular string.
Replace A Line In A Text File
I would like to replace a single line in a text file. The initially i only had to have a single line so I could just use fputs to rewrite the entire file. Now I have three lines and want to selectively replace one of them..
Search File For Line And Replace With Update
I am trying to search through a file for a line. My line that I will be searching is in a cron flat file. I need to search that file for a line simirlar to: 59 23 * * * wget -q http://www.site.com/runPage.php?usr=name When the line is found, I need to make changes to it. I have read the file into a variable with fread, is that the best way to get this information for the type of search and replace I am trying to do? From what I have read in past posts, it seems like strstr is a quick way to go or would strpos be? Or, do I have to do more than that?
How To Replace Define In A Require File With Mysql?
I have a file linked with require into my program with statements like: define("_ADDRESS","Address"); define("_CITY","City"); I would like to replace this with a mysql table with these two fields (out of many other fields). How can I do that?
Read Log File With PHP?
It turns out that opendir and a number of other cool PHP features are disabled by my host. I've had to deal with similar issues before and have worked around them (that's part of the fun.) What I am trying to do is create a PHP file which will delete specific files from a directory that are more than 24 hours old. My question is this: Is this possible without readdir and opendir? Can I use fopen and fread as alternatives in my solution? The key problem that I see is that I can read the log file but where do I begin to parse the log file into file names and dates? Typical entries in my log file would look like this: 2007/05/02 2:00:31 : File http://www.example.com/myFile.zip Sent to someone@example.com 2007/05/02 2:08:31 : File http://www.example.com/myPic.jpg Sent to someone2@anotherexample.com I guess I would have to somehow define the format of each entry? If so how would I do this. Is this idea even realistic with PHP?
Read A File Name?
Is it possible to read a file name from inside a file, then set that name to a variable?
Can't Get Php To Read Ini File.
My configuration is Apache/2.0.59 (Unix) mod_ssl/2.0.59 OpenSSL/0.9.7d PHP/5.0.4 on Solaris 10. phpinfo() lists the location of php.ini as /usr/local/apache/conf and my php.ini file is there but for some reason it does not appear to be being read by php. I have defined things such as upload_tmp_dir in that file yet even with restarting apache I am not seeing this reflected in phpinfo().
Php Read A File
I am using the following to read the contents of a file. $Tp = fopen("./orders/T" . $oid , "r" ); This usually works, however the order directory is password protected making this code produce an error: --Warning: file("./orders/T1166964955") - No such file or directory in...-- Is there any way whicj I can supply the usernameassword to this code : $Tp = fopen("./orders/T" . $oid , "r" ); or will I have to have the file T1166964955 in a non-secure area.
File Read
Im writing a program to enable a user to select a part of an MP3 song and save it. Now I wrote a quick test before I started on the final app, and that worked fine. Code:
File Read
I have a file. I want to read in the first 64 bytes, as 8, 8 byte integers. Does anyone know how to do this? It is a binary file, so I was thinking to open it up as binary, read($fp, , then convert it to a number somehow?
Another Read File Question.
I have been trying to read portions of a text file into variables that will display on a page and confirm adding them to mySQL. I have found the posts on how to read parts of a file when there is something that you can search for like PHP Code:
Read First 10 Lines From A File
I have an ASCII file with each data record on a separateline. Each field is delimited with a TAB (ASCII 9) character. Now i want to read the first 10 lines and show them on my site. This is what i already have reading the first line: $fname = "http://www.somedomain.com/file.txt"; $fd = fopen($fname, "r"); if ($fd) { if (!feof ($fd)) { $buffer = fgets($fd, 4096); $field = split(chr(9), trim($buffer)); $field0 = "$field[0]"; $field1 = "$field[1]"; } fclose($fd); } echo ("$field0 - $field1"); How can i do this voor the first 10 lines?
Read A File Of String Into What?
Pardon the simple question, but I have just begun to learn PHP. So far so good - all the examples in my books actually work. One thing that none of them address is how to read a file of strings (like names or URLs or whatever) into something so that they can be deleted, modified or a new one added. In a language like Perl/TK or Delphi a listbox is used if you want to edit line by line or a memo box if you want to edit like you are in Kwrite. All the examples assume that I want to enter data into a Text area or Listbox by keyboard, then read it back in. Never the other way around. I can use a Fget routine and read the file to the screen, but not to anything in which I can edit yet. So far I have learned a ton of stuff trying, but haven't made it work yet. Should I be reading the data into a Textarea, a Listbox or something else?
File Read Problems !
I am trying to read files from a remote location and only get part of the file. I do not get any errors but seem to not get the last few bytes. Why? I thought that it was because of magic_quotes, so I tried to set that right ... set_magic_quotes_runtime(0); $fd = fopen ($filelink,"rb"); $contents = fread ($fd, 100000); fclose ($fd); set_magic_quotes_runtime(get_magic_quotes_gpc());
Read File From Harkdisk
I want to know how to read file from HArd Disk (assume it is sequential file)or CD ROM or any other drive on LAN (But not on web) What is the way to read Excel or Access file from HArd disk The profrom will be running on web and read data from Local Hard Disk or Cd ROM.
Trimming Everything Off Of A File After A Tag Has Been Read.
I am having now is that I have a sciprt so people can add news, only problem is that after it is added I get a bit of access writing on the end, <br> and other stuff different every time. Can someone do an example of how to trim the end of the file after the it sees the tag [/NTBL]. The trick is there is more then one [/NTBL] tag and it needs to only trim everythign after the last time the tag is seen.
Need To Read The File Contents
I have a small problem.i need to read the file contents from the url.here is the desc of the problemthe file(local file with compelte path) name should pass thru url(no file upload option)so i need to read that file and store that content in the databasehere is the examplehttp://example.com/read.php?file="D://text.txt"Once i enter this url in the browser, i need to read that text.txt file and store the content of text.txt into DB.
Read From File Into Array
I see what my problem is but not sure what I need to change. I'm reading a single number from a file that's fed into an array but the array doesn't want to print out its output. $oncall=array(); $oncall[1]="msims"; $oncall[2]="dtilbury"; $oncall[3]="jma"; $oncall[4]="jweaver"; $oncall[5]="cirwin"; $filename="oncall/.oncall"; $n=file_get_contents($filename); echo "$oncall[$n]"; This prints nothing. But when I comment out the file_get_contents and simply do $n="2" the array prints out dtilbury like it should. My guess is the error lies in how $n is being assigned from the file_get_contents. Any thoughts?
Read A File Below Root
How can I include a file from below the Root dir, other than using: include "../../filename.inc.php";
Some Gzip File To Read
I have some gzip file to read.,I can able to read. But i need to edit the content of a gzip file, I can read the contents, and when i try to write it just create an another file. But i need it to be saved as the same file so that i can read from the same file in future...
Saving CSV File To Read From Php
Let me explain what I am trying to do first. I want to upload a .csv file from a form page to the redhat server. Uploading is working fine, I could upload the .csv file to the server. But when I open the uploaded file using VI editor in the server, I see "^M" characters and all CSV formats are disappeared. Also "fgetcsv()"...
How Read ONLY Last Row ASCII File
PHP code ..... <? //Open file. $file=fopen("file.txt","r"); //read file so long when it isn't end. while (!feof($file)) { //read and print row + LF. $rivi=fgets($file,1024); print "$row<BR>"; } //Close file. fclose($file); ?> .....is read file(ascii) and print it display.
Read Data From TXT File
Open a text file which will look something like this: QuoteLink 1 http://www.blahblah.com/1651561 Link 2 http://www.etc.com/34324 Link 3 http://www.sdfkjsdf.com/12343423 basically its a "Link n" text followed by a URL text in the format of "http://www.page.com/random numbers" What I would like the php script to do is to read "Link n" text and output it with the a http link to the URL which follows it. That is it should look something like this in the output: Link 1 Link 2 Link 3 I have learned how to read a text file with php so far but I have no idea how to make it read up to a point and assign the read value to an array.
Read Msword Doc File
iam using linux server........how to read msword doc file and how to stores the data in a variable.....
Strpos(), Read A File Name
I am trying to read a file name. i want this code to check if the filename conatains a dash or not and i am trying strpos() if((strpos($filename, " - ") === false) ¦¦ (strpos($filename, "-") === false)){ $splitby = "test";//do stuff if it does not contain a " - " } else{ if(strpos($filename, " - ") === true){ $splitby = " - "; } elseif(strpos($filename, "-") === true){ $splitby = "-"; } } echo $splitby; nothing comes up for $splitby. Am I doing this correctly?
|