Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: help me solve a file edit problem

  1. #1
    111222 is offline Newbie
    Join Date
    Sep 2007
    Posts
    5
    Rep Power
    0

    Exclamation help me solve a file edit problem

    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".

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Jordan Guest
    Code:
    //To open/read file contents:
    $myFile "filename.ext";
    $fh fopen($myFile'r');
    $data fread($fh9999999);
    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); 

  4. #3
    Jordan Guest
    Here is better code:

    Code:
    //To open/read file contents:
    $myFile "filename.ext";
    $fh fopen($myFile'r+');
    $data fread($fh9999999);

    //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); 

  5. #4
    111222 is offline Newbie
    Join Date
    Sep 2007
    Posts
    5
    Rep Power
    0
    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.

  6. #5
    NeedHelp Guest
    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'.

  7. #6
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    I' pretty sure you can do this using the FTP wrapper along with some file system functions.

  8. #7
    111222 is offline Newbie
    Join Date
    Sep 2007
    Posts
    5
    Rep Power
    0
    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)

  9. #8
    NeedHelp Guest
    The file system commands will still not help him if he doesn't own the file (doesn't have write permission).

  10. #9
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    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.

  11. #10
    111222 is offline Newbie
    Join Date
    Sep 2007
    Posts
    5
    Rep Power
    0
    i own the file!!! i just want to edit it without givin him a command.
    how can i do that?

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Edit an XML file from JSP (XPath)
    By toto_7 in forum Java Help
    Replies: 14
    Last Post: 05-18-2011, 05:22 AM
  2. help me to solve this problem..please..
    By purple_coat in forum C and C++
    Replies: 3
    Last Post: 02-07-2011, 01:10 PM
  3. Edit text file on server.
    By Logan in forum Visual Basic Programming
    Replies: 1
    Last Post: 08-04-2010, 01:59 AM
  4. Edit file from Browser.
    By xsell in forum PHP Development
    Replies: 3
    Last Post: 12-09-2009, 08:48 AM
  5. C++: How would you solve this problem?
    By Lance in forum C and C++
    Replies: 27
    Last Post: 01-09-2009, 07:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts