...

View Full Version : No error, but don't post to file ?!?!?!



Peuplarchie
07-08-2007, 06:26 AM
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

// 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 ."\n\r";
//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 "\n\r"."copiage de fichier Fin"."\n\r";
echo "\n\r"."Redirection en-cours ......"."\n\r";



fclose($fp);



?>

_Aerospace_Eng_
07-08-2007, 06:49 AM
This line is wrong

$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

$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

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

"nr"
They should be

"\n\r"

Peuplarchie
07-08-2007, 07:14 AM
still it doesn't work....

_Aerospace_Eng_
07-08-2007, 07:26 AM
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.

Peuplarchie
07-08-2007, 07:54 AM
name and ext of a file

_Aerospace_Eng_
07-08-2007, 07:56 AM
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?

Peuplarchie
07-08-2007, 08:15 AM
same server, other folder.

Peuplarchie
07-08-2007, 08:57 PM
I have an error of fopen, failed to open stream http wrapper does not support writeable connections

_Aerospace_Eng_
07-08-2007, 10:59 PM
Thought you said you didn't have any errors?
Change this


$file="http://rsv.peuplies.info/2007/".$data;//define the file to open
to this


$file="2007/".$data;//define the file to open

Peuplarchie
07-08-2007, 11:09 PM
It's done, RESOLVED
Thanks !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum