I made a ftp_put_contents function.
hope you enjoy.
}
else {$fpc_file_name=$fpc_path_and_name;
}//Create local temp dirif (!file_exists($cfg_temp_folder)) {
if (!mkdir($cfg_temp_folder,0777)) {
echo"Unable to generate a temporary folder on the local server -$cfg_temp_folder.
";
die();
}
}//Create local file in temp dirif (!file_put_contents(str_replace("//","/",$cfg_temp_folder.$fpc_file_name),$fpc_content)) {
echo"Unable to generate the file in the temporary location - ".str_replace("//","/",$cfg_temp_folder.$fpc_file_name).".
";
die();
}//Connection to the FTP Server$fpc_ftp_conn=ftp_connect("$cfg_ftp_server");//Check connectionif (!$fpc_ftp_conn) {
echo"Could not connect to server $cfg_ftp_server.
";
die();
}
else {// login
// check username and passwordif (!ftp_login($fpc_ftp_conn,"$cfg_user","$cfg_pass")) {
echo"User or password.
";
die();
}
else {//Document Rootif (!ftp_chdir($fpc_ftp_conn,$cfg_document_root)) {
echo"Error to set Document Root.
";
die();
}//Check if there are folders to createif ($cotains_slash) {//Check if have folders and is not just the file nameif (count($fpc_path_and_name_array) >1) {//Remove last array$fpc_remove_last_array=array_pop($fpc_path_and_name_array);//Checks if there slashs on the pathif (substr($fpc_path_and_name,0,1) =="/") {$fpc_remove_first_array=array_shift($fpc_path_and_name_array);
}//Create each folder on ftpforeach ($fpc_path_and_name_arrayas$fpc_ftp_path) {
if (!@ftp_chdir($fpc_ftp_conn,$fpc_ftp_path)) {
if (!ftp_mkdir($fpc_ftp_conn,$fpc_ftp_path)) {
echo"Error creating directory$fpc_ftp_path.
";
}
else {
if (!ftp_chdir($fpc_ftp_conn,$fpc_ftp_path)) {
echo"Error go to the directory$fpc_ftp_path.
";
}
}
}
}
}
else {
}
}//Check upload fileif (!ftp_put($fpc_ftp_conn,$fpc_file_name,str_replace("//","/",$cfg_temp_folder.$fpc_file_name),FTP_ASCII)) {
echo"File upload $fpc_path_and_name failed!
";
die();
}
else {
if (!unlink(str_replace("//","/",$cfg_temp_folder.$fpc_file_name))) {
echo"Error deleting temporary file.
";
die();
}
else {
echo"File upload $cfg_site_link".str_replace("//","/","/$fpc_path_and_name")." successfully performed.
";
}
}//Close connection to FTP serverftp_close($fpc_ftp_conn);
}
}
}#Sample$content_file=""-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
TitleTest
";ftp_put_contents("test.php",$content_file);?>