Professional Web Applications Themes

[PHP] magical file writing truncation - PHP Development

[snip] $newFile = "xml/".$type."/".$now.".xml"; while(file_exists($newFile)) $newFile = "xml/".$type."/".$now++.".xml"; $text = $_POST['text']; $text = urlencode(stripslashes(nl2br($text))); [/snip] At this point (for testing putposes) I would echo "$text"; and start looking for clues. If I were a betting man I would have to say that there is some problem with quotes within the text. I hope that this points you in the right direction. Have a pleasant and fruitful day!...

  1. #1

    Default RE: [PHP] magical file writing truncation

    [snip]
    $newFile = "xml/".$type."/".$now.".xml";
    while(file_exists($newFile))
    $newFile = "xml/".$type."/".$now++.".xml";
    $text = $_POST['text'];
    $text = urlencode(stripslashes(nl2br($text)));
    [/snip]

    At this point (for testing putposes) I would echo "$text"; and start
    looking for clues. If I were a betting man I would have to say that
    there is some problem with quotes within the text. I hope that this
    points you in the right direction.

    Have a pleasant and fruitful day!
    Jay Blanchard Guest

  2. #2

    Default Re: [PHP] magical file writing truncation

    > [snip]
    > $newFile = "xml/".$type."/".$now.".xml";
    > while(file_exists($newFile))
    > $newFile = "xml/".$type."/".$now++.".xml";
    > $text = $_POST['text'];
    > $text = urlencode(stripslashes(nl2br($text)));
    > [/snip]
    >
    > At this point (for testing putposes) I would echo "$text"; and start
    > looking for clues. If I were a betting man I would have to say that
    > there is some problem with quotes within the text. I hope that this
    > points you in the right direction.
    been doing some more testing. $text seems to stay intact throughout, it is
    exactly what it should be. if i do an fwrite( $fp, $text ) then it writes
    perfectly all contents of the $text as i would expect. i shouldn't get any
    problems with quotes or other characters as the whole lot is urlencode()'d
    > Have a pleasant and fruitful day!
    wow, everyone on this list should be THAT cheery :) thanks mate, you too!


    Skate Guest

  3. #3

    Default Re: [PHP] magical file writing truncation


    > > [snip]
    > > $newFile = "xml/".$type."/".$now.".xml";
    > > while(file_exists($newFile))
    > > $newFile = "xml/".$type."/".$now++.".xml";
    > > $text = $_POST['text'];
    > > $text = urlencode(stripslashes(nl2br($text)));
    > > [/snip]
    > >
    ack, sorry to double post...

    it appears that it actually reverse truncates the $text... so it cuts off
    the beginning of the text, and leaves the end bit. i can understand this
    happening as an XML interpreter as the <html> tags get in the way, but these
    are urlencoded, and writing to the file has nothing to do with the XML
    functions.

    i dunno if this is maybe a bug in PHP? i can't get my head round why it
    looses have my string in 2 lines...

    thanks again for the help...


    Skate Guest

  4. #4

    Default RE: [PHP] magical file writing truncation

    [snip]
    > > [snip]
    > > $newFile = "xml/".$type."/".$now.".xml";
    > > while(file_exists($newFile))
    > > $newFile = "xml/".$type."/".$now++.".xml";
    > > $text = $_POST['text'];
    > > $text = urlencode(stripslashes(nl2br($text)));
    > > [/snip]
    > >
    ack, sorry to double post...

    it appears that it actually reverse truncates the $text... so it cuts
    off
    the beginning of the text, and leaves the end bit. i can understand this
    happening as an XML interpreter as the <html> tags get in the way, but
    these
    are urlencoded, and writing to the file has nothing to do with the XML
    functions.
    [/snip]

    Let's work backwards then. Instead of
    $text = urlencode(stripslashes(nl2br($text)));

    try
    $text = urlencode(nl2br($text));
    echo "$text";

    Can you post the first couple of raw lines of text and then the echo'd
    output?
    Jay Blanchard Guest

  5. #5

    Default RE: [PHP] magical file writing truncation

    [snip]
    okay, the first few lines of raw text are as follows... it's a chat log
    btw...

    Session Start (Yahoo! - fatcubanskate:the_lady_in_waiting1982): Thu Jul
    10
    21:23:42 2003 [21:23] the_lady_in_waiting1982: hey y!!! [21:24]
    fatcubanskate: hey sugar [21:24] fatcubanskate: how\'s thing? [21:25]
    the_lady_in_waiting1982: you know we could do a whole roll playing
    thing,
    that would be a big as turn on [21:25] fatcubanskate: oh really? like...
    i
    pretend to be a pirate? [21:25] fatcubanskate: raaar!!!

    and then the first few lines of the echo'd output...

    Session+Start+%28Yahoo%21+-+fatcubanskate%3Athe_lady_in_waiting1982%29%3
    A+Th
    u+Jul+10+21%3A23%3A42+2003+%3Cbr+%2F%3E%0D%0A%5B21 %3A23%5D+the_lady_in_w
    aiti
    ng1982%3A+hey+y%21%21%21+%3Cbr+%2F%3E%0D%0A%5B2 1%3A24%5D+fatcubanskat
    e%3A
    +hey+sugar+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcuba nskate%3A+how%5C%27s+t
    hing
    %3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+the_lady_in_wa iting1982%3A+you+know+
    we+c
    ould+do+a+whole+roll+playing+thing%2C+that+would+b e+a+big+as+turn+on+%3C
    br+%
    2F%3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+oh+reall y%3F+like...+i+pretend
    +to+
    be+a+pirate%3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+fat cubanskate%3A+raaar%21
    %21%
    21
    [/snip]

    OK, put stripslashes back in and show the echo'd out put again.




    --
    PHP General Mailing List ([url]http://www.php.net/[/url])
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Jay Blanchard Guest

  6. #6

    Default Re: [PHP] magical file writing truncation

    [snip]
    Session+Start+%28Yahoo%21+-+fatcubanskate%3Athe_lady_in_waiting1982%29%3
    A+Th
    u+Jul+10+21%3A23%3A42+2003+%3Cbr+%2F%3E%0D%0A%5B21 %3A23%5D+the_lady_in_w
    aiti
    ng1982%3A+hey+y%21%21%21+%3Cbr+%2F%3E%0D%0A%5B2 1%3A24%5D+fatcubanskat
    e%3A
    +hey+sugar+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcuba nskate%3A+how%5C%27s+t
    hing
    %3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+the_lady_in_wa iting1982%3A+you+know+
    we+c
    ould+do+a+whole+roll+playing+thing%2C+that+would+b e+a+big+as+turn+on+%3C
    br+%
    2F%3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+oh+reall y%3F+like...+i+pretend
    +to+
    be+a+pirate%3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+fat cubanskate%3A+raaar%21
    %21%
    21
    [/snip]

    OK, put stripslashes back in and show the echo'd out put again.

    -------------

    $text = urlencode(stripslashes(nl2br($text)));
    print $text;

    ...........

    Session+Start+%28Yahoo%21+-+fatcubanskate%3Athe_lady_in_waiting1982%29%3A+Th
    u+Jul+10+21%3A23%3A42+2003+%3Cbr+%2F%3E%0D%0A%5B21 %3A23%5D+the_lady_in_waiti
    ng1982%3A+hey+y%21%21%21+%3Cbr+%2F%3E%0D%0A%5B2 1%3A24%5D+fatcubanskate%3A
    +hey+sugar+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcuba nskate%3A+how%27s+thing%3F
    +%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+the_lady_in_waiti ng1982%3A+you+know+we+coul
    d+do+a+whole+roll+playing+thing%2C+that+would+be+a +big+as+turn+on+%3Cbr+%2F%
    3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+oh+really%3 F+like...+i+pretend+to+be+
    a+pirate%3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+fatcub anskate%3A+raaar%21%21%21


    Skate Guest

  7. #7

    Default RE: [PHP] magical file writing truncation

    [snip]
    OK, put stripslashes back in and show the echo'd out put again.

    -------------

    $text = urlencode(stripslashes(nl2br($text)));
    print $text;

    [/snip]

    I didn't see anything right off of the bat. You may want to output the
    text both ways and then compare them using
    [url]http://us3.php.net/manual/en/function.strcmp.php[/url]

    Jay Blanchard Guest

  8. #8

    Default RE: [PHP] magical file writing truncation

    [snip]
    i really can't get my head around this one at all. could it possibly be
    a
    windows issue??? i know windows can be an in dealing with files,
    but i
    can't see how it could pick up on a variable inside PHP and truncate it?
    [/snip]

    I just have one more thought because you brought up Windows. Change the
    name of the variable "$text" ..... text might just be one of those
    reserved or key words....
    Jay Blanchard Guest

Similar Threads

  1. Writing a text file to the file system
    By cwbp in forum ASP.NET Security
    Replies: 3
    Last Post: April 2nd, 10:52 AM
  2. Replies: 10
    Last Post: April 27th, 05:04 PM
  3. Setting the file permissions of a file I'm writing to
    By Dan Anderson in forum PERL Beginners
    Replies: 1
    Last Post: December 10th, 04:13 AM
  4. File Access error - writing to .txt file
    By Steve C. Orr, MCSD in forum ASP.NET General
    Replies: 1
    Last Post: July 18th, 10:35 PM
  5. Replies: 1
    Last Post: July 4th, 12:02 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139