how can i make the php to open a file, search a specific sentance in it, replace it to another sentance, and then save the file automaticly without "777 command".
help me solve a file edit problem
Started by 111222, Dec 12 2007 08:28 AM
11 replies to this topic
#1
Posted 12 December 2007 - 08:28 AM
|
|
|
#2
Guest_Jordan_*
Posted 12 December 2007 - 09:21 AM
Guest_Jordan_*
//To open/read file contents:
$myFile = "filename.ext";
$fh = fopen($myFile, 'r');
$data = fread($fh, 9999999);
fclose($fh);
//Search the data and replace a string:
$data = str_replace("STRING HERE", "REPLACE HERE", $data);
//To write to a file:
$myFile = "filename.ext";
$fh = fopen($myFile, 'a');
fwrite($fh, $data);
fclose($fh);
#3
Guest_Jordan_*
Posted 12 December 2007 - 09:25 AM
Guest_Jordan_*
Here is better code:
//To open/read file contents:
$myFile = "filename.ext";
$fh = fopen($myFile, 'r+');
$data = fread($fh, 9999999);
//Search the data and replace a string:
$data = str_replace("STRING HERE", "REPLACE HERE", $data);
//To write to a file:
fwrite($fh, $data);
fclose($fh);
#4
Posted 12 December 2007 - 11:01 AM
i sayed witout 777 commend.
when i do your programing
i get permission dineded
i have 644 commend.
when i do your programing
i get permission dineded
i have 644 commend.
#5
Guest_NeedHelp_*
Posted 12 December 2007 - 11:03 AM
Guest_NeedHelp_*
That is an OS issue, not a PHP issue. You say 777 command you need to either be the user that owns the file or in the group that owns the directory or chmod the file to '777'.
#6
Posted 12 December 2007 - 11:07 AM
#7
Posted 12 December 2007 - 11:17 AM
hah!? you dont helped me.
i want it to edit the file without commend it (the orginal commend is 644)
plez give me a script to edit the file with the orginal commend (644)
i want it to edit the file without commend it (the orginal commend is 644)
plez give me a script to edit the file with the orginal commend (644)
#8
Guest_NeedHelp_*
Posted 12 December 2007 - 11:18 AM
Guest_NeedHelp_*
The file system commands will still not help him if he doesn't own the file (doesn't have write permission).
#9
Posted 12 December 2007 - 11:59 AM
Well if he doesn't own the file, it is impossible to write or execute that file. That's why permissions exist.
However he never said he didn't own the file. Assuming he uploaded the file, the FTP user does own the file and has mod 6 - meaning he can read (4) and (+) write (2). The php user only has a mod of 4 meaning he can only read. Which is why, using the file system commands with the php user will not work, but using the file system commands with the FTP user will...
However he never said he didn't own the file. Assuming he uploaded the file, the FTP user does own the file and has mod 6 - meaning he can read (4) and (+) write (2). The php user only has a mod of 4 meaning he can only read. Which is why, using the file system commands with the php user will not work, but using the file system commands with the FTP user will...
#10
Posted 12 December 2007 - 12:07 PM
i own the file!!! i just want to edit it without givin him a command.
how can i do that?
how can i do that?
#11
Posted 12 December 2007 - 12:36 PM
As I said before:
A combination of the code snippets found in the PHP manual [click the links I provided] and what Jordan posted above should be all you need.
Sidewinder said:
I' pretty sure you can do this using the FTP wrapper along with some file system functions.
A combination of the code snippets found in the PHP manual [click the links I provided] and what Jordan posted above should be all you need.
#12
Posted 12 December 2007 - 03:38 PM
You are either going to have to chmod it manually or chmod it by code as Sidewinder has suggested. Once you have done that then use Jordan's code. If you chmod it by code you can always chmod it back to what it was at the end.


Sign In
Create Account

Back to top









