Problem with PHP.

Discussion in 'PHP' started by Jake-Johnson, Oct 11, 2009.

  1. #1
    Here is what I'm trying to do.

    I want to use PHP's fwrite function in order to write PHP to another file, like so:

    
    $fh = fopen($src,'w')or die("Error");
    $data = "<?php //Insert whatever code here ?>";
    fwrite($fh,$data);
    fclose($fh);
    
    PHP:
    In otherwords, I would like to write a script using PHP to another PHP file. Anyone know how this would be possible?
     
    Jake-Johnson, Oct 11, 2009 IP
  2. saeedsjaan

    saeedsjaan Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #2
    i dont think so man, if you get know do tell me.. thanks

    bestfreesms.com
     
    saeedsjaan, Oct 11, 2009 IP
  3. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well, you're already doing it. What is wrong with it? Should work just fine.
     
    premiumscripts, Oct 11, 2009 IP
  4. goliath

    goliath Active Member

    Messages:
    308
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Is there some reason that the code above doesn't work for you?

    Of course, it will tak ea little more to publish actual code that way, you need to get comfortable properly escaping string characters, too. But you've got the basics of it right there.
     
    goliath, Oct 11, 2009 IP
  5. phpdoctor22

    phpdoctor22 Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Are you getting any errors?
     
    phpdoctor22, Oct 11, 2009 IP
  6. picos

    picos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #6
    CHMOD 666, dont forget.
     
    picos, Oct 13, 2009 IP
  7. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #7
    What's wrong with it. Should work fine unless I am missing something. Though setting a variable for the data is almost completely useless unless you are going to being doing other things to the text before you put it into the file.
     
    Pudge1, Oct 13, 2009 IP
  8. Jake-Johnson

    Jake-Johnson Peon

    Messages:
    839
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Whitespace error is what I get when I try this on the line with PHP.

    What do you mean by CHMOD 666?
     
    Jake-Johnson, Oct 13, 2009 IP
  9. goliath

    goliath Active Member

    Messages:
    308
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #9
    maybe it's because you're invoking the PHP parser for only a single comment in your exported code?
     
    goliath, Oct 13, 2009 IP
  10. Earn at Home

    Earn at Home Peon

    Messages:
    240
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    every file has its own CHMOD permission, once the target file is CHMOD 666 then its editable, writable by you as the owner. if you have problems with CHMOD, try changing the file CHMOD from 666 to 777
     
    Earn at Home, Oct 13, 2009 IP