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".
Code://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);
Here is better code:
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);
i sayed witout 777 commend.
when i do your programing
i get permission dineded
i have 644 commend.
Last edited by 111222; 12-12-2007 at 11:15 AM.
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'.
I' pretty sure you can do this using the FTP wrapper along with some file system functions.
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)
The file system commands will still not help him if he doesn't own the file (doesn't have write permission).
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...
Last edited by John; 12-12-2007 at 12:02 PM.
i own the file!!! i just want to edit it without givin him a command.
how can i do that?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks