grasmanek94 Posted May 25, 2010 Share Posted May 25, 2010 Hello I wrote a include and index file which uses the include. it is based on a FTP connection, i need to 'save' the FTP stream to a variable that can be shared between the include+index. my index: <?php include('pini12.php'); $host = "*"; $user = "*"; $password = "*"; $path = "FTPRoot/"; $connid = FTP_pini_StartConnection($host,$user,$password,$path); $result = FTP_pini_Set("file.txt","key1","value1"); print("$result<BR>"); $result = FTP_pini_IntSet("file.txt","intkey1",89864); print("$result<BR>"); $result = FTP_pini_Get("file.txt","key1"); print("$result<BR>"); $result = FTP_pini_IntGet("file.txt","intkey1"); print("$result<BR>"); ftp_close($connid); ?> and my include: <?php /********************************************************** *********************************************************** ** Pini v1.2 ********************************************** ** Original script Dini wrapped by DowNlOaD_ & Gamer_Z **** ** Pini *************************************************** *********************************************************** **********************************************************/ function pini_Exists($filename) { return is_file($filename); } function pini_Remove($filename) { return unlink($filename); } function pini_Create($filename) { if (pini_Exists($filename)) { return 1; } $fhnd=fopen($filename,"w+"); fclose($fhnd); return 1; } function pini_Get($filename,$key) { $string = ""; if(file_exists($filename)) { $lines = file("$filename"); foreach ($lines as $line) { $line = rtrim($line); if(stristr($line, $key." = ")) { $string = str_replace($key." = ","",$line); }else if(stristr($line, $key." =")) { $string = str_replace($key." =","",$line); }else if(stristr($line, $key."=")) { $string = str_replace($key."= ","",$line); }else if(stristr($line, $key."=")) { $string = str_replace($key."=","",$line); } } } return $string; } function pini_IntGet($filename,$key) { return strval(pini_Get($filename,$key)); } function pini_Set($filename,$key,$value) { if(!file_exists($filename)) { pini_Create($filename); } $lines = file($filename); $found = 0; $random = rand(5000,999999); $tempfilename = "$random"."tempfile.tmp"; $fp = fopen($tempfilename, 'w+'); foreach ($lines as $line) { $line = rtrim($line); if(stristr($line, $key." = ")) { $line = $key." = ".$value; }else if(stristr($line, $key." =")) { $line = $key." =".$value; }else if(stristr($line, $key."= ")) { $line = $key."= ".$value; }else if(stristr($line, $key."=")) { $line = $key."=".$value; } fwrite($fp,$line); fwrite($fp,"\r\n"); } fclose($fp); @unlink($filename); rename($tempfilename,$filename); if($found == 0){ $string = $key."=".$value; $fh = fopen($filename, 'a+'); fwrite($fh, $string); fwrite($fh, "\r\n"); fclose($fh); } return 1; } function pini_IntSet($filename,$key,$value) { return pini_Set($filename,$key,"$value"); } global $pini_ftpconnection; function FTP_pini_StartConnection($host,$user,$password,$path){ if($pini_ftpconnection != 0){ print("End your first connection!"); } else { $pini_ftpconnection = ftp_connect($host); if($pini_ftpconnection) { @ftp_login($pini_ftpconnection, $user, $password); $parent = substr($path, 0, strrpos($path, "/")); ftp_chdir($pini_ftpconnection,$path); } return $pini_ftpconnection; } } function FTP_pini_Exists($filename) { if(ftp_size($pini_ftpconnection,$filename) != (-1)){return 1;} return 0; } function FTP_pini_Remove($filename) { return ftp_delete($pini_ftpconnection, $filename); } function FTP_pini_Create($filename) { $fhnd=fopen($filename,"w+"); fclose($fhnd); $status = 0; if(FTP_pini_Exists($filename)) { $status = 2; } else { if(ftp_put($pini_ftpconnection, $filename,$filename, FTP_BINARY)) { $status = 1; } } unlink($filename); return $status; } function FTP_pini_Get($filename,$key) { $toreturn = ""; if(ftp_get($pini_ftpconnection, $filename,$filename, FTP_BINARY)) { $toreturn = pini_Get($filename,$key); unlink($filename); } return $toreturn; } function FTP_pini_IntGet($filename,$key) { return strval(FTP_pini_Get($filename,$key)); } function FTP_pini_Set($filename,$key) { $status = 0; if(ftp_get($pini_ftpconnection, $filename,$filename, FTP_BINARY)) { if(pini_Set($filename,$key,$value)){ if(ftp_delete($pini_ftpconnection, $filename)) { if(ftp_put($pini_ftpconnection, $filename,$filename, FTP_BINARY)) { unlink($filename); $status = 1; } } } } return $status; } function FTP_pini_IntSet($filename,$key,$value) { return FTP_pini_Set($filename,"$key"); } ?> and now i want to use a FTP function ,he connects OK, but when I want to use a function it just returns a warning that the stream is NULL.. any help? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 You need to pass the connection ID to any function that needs it. Ken Quote Link to comment Share on other sites More sharing options...
grasmanek94 Posted May 25, 2010 Author Share Posted May 25, 2010 okay you see the code? i passed it so what's wrong? or how do i pass it?... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 You did not pass it in every function. You have this statement outside of all the function definitions: <?php global $pini_ftpconnection; ?> That does absolutely nothing, since global only works inside a function definition. If you don't want to pass the connection id to every function, move that statement inside every function. Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.