Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post No error, but don't post to file ?!?!?!

    Salut !
    Here is a piece of code which it bring me to drink..lol

    I need to find the error, it don't give me an error but it don't copy "codesource" to "http://rsv.peuplies.info/2007/".$data"


    Can somebody help me on this ?

    Thanks to viewers and those who take their time to help me on my many questions !!!1


    PHP Code:
    <?php

    // set file to read
    $file 'choix_message.txt' ;
    // read file into string
    $data file_get_contents($file) or die('Could not read file!');



    echo 
    "copiage de fichier debut"."\n\r";

    $strip stripslashes($_POST['codesource']);


    $file="http://rsv.peuplies.info/2007/".$data";//define the file to open
    $lines=file($file);//load the lines to an array
    $insert_line = 75;//the line to insert at...could be a post variable
    $insert_text = $strip ."
    nr";
    //this could be a post variable, but at any case make sure to append the var with the new line, otherwise it will run together
    $temp="";//start a temp variable to work with
    $count=1;//initialize a counter


    foreach($lines as $line){
    ($count != $insert_line) ? $temp .= $line : $temp .= $insert_text . $line;
    $count++;
    }



    $fp = fopen($file,'w');
    // write string to file
    $write = fwrite($fp, $temp);
    fclose($fp);
    echo "
    nr"."copiage de fichier Fin"."nr";
    echo "
    nr"."Redirection en-cours ......"."nr";



    fclose($fp);



    ?>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This line is wrong
    PHP Code:
    $file="http://rsv.peuplies.info/2007/".$data";//define the file to open 
    You can see its wrong to in the code you posted because everything after it i is a string (red color). It should be
    PHP Code:
    $file="http://rsv.peuplies.info/2007/".$data;//define the file to open 
    Now with the code change, look at the syntax highlighting. Its changed.
    PHP Code:
    <?php

    // set file to read
    $file 'choix_message.txt' ;
    // read file into string
    $data file_get_contents($file) or die('Could not read file!');



    echo 
    "copiage de fichier debut"."\n\r";

    $strip stripslashes($_POST['codesource']);


    $file="http://rsv.peuplies.info/2007/".$data;//define the file to open
    $lines=file($file);//load the lines to an array
    $insert_line 75;//the line to insert at...could be a post variable
    $insert_text $strip ."nr";
    //this could be a post variable, but at any case make sure to append the var with the new line, otherwise it will run together
    $temp="";//start a temp variable to work with
    $count=1;//initialize a counter


    foreach($lines as $line){
    (
    $count != $insert_line) ? $temp .= $line $temp .= $insert_text $line;
    $count++;
    }



    $fp fopen($file,'w');
    // write string to file
    $write fwrite($fp$temp);
    fclose($fp);
    echo 
    "nr"."copiage de fichier Fin"."nr";
    echo 
    "nr"."Redirection en-cours ......"."nr";



    fclose($fp);



    ?>
    I also noticed you have things like
    Code:
    "nr"
    They should be
    Code:
    "\n\r"
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    still it doesn't work....

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What is inside of
    choix_message.txt

    What is happening now is its trying to open the path plus the contents of the file "choix_message.txt". If the file doesn't contain the path to another file, its not going to open because the file doesn't exist.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    name and ext of a file

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Wait just noticed this, are you trying to write to a file on another server or is it on the same server as the script?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    same server, other folder.

  • #8
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    I have an error of fopen, failed to open stream http wrapper does not support writeable connections

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Thought you said you didn't have any errors?
    Change this
    PHP Code:
    $file="http://rsv.peuplies.info/2007/".$data;//define the file to open 
    to this
    PHP Code:
    $file="2007/".$data;//define the file to open 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    It's done, RESOLVED
    Thanks !


  •  

    Posting Permissions

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