/**
* Implementation of hook_form_alter. Define the form for saving to ftp.
*/
function savetoftp_form_alter($form_id, &$form) {
if ($form_id == 'regpage_node_form') {
$form['savetoftp'] =
array(
'#type' => 'fieldset',
'#title' =>
t('FTP Server settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 30,
);
$form['savetoftp']['ftp_server'] =
array(
'#type' => 'textfield',
'#default_value' =>
variable_get('ftp_server',
'www.sfsu.edu'),
'#maxlength' => 50,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
t('Enter your FTP Server'),
);
$form['savetoftp']['ftp_username'] =
array(
'#type' => 'textfield',
'#maxlength' => 50,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
t('Enter your FTP Username'),
);
$form['savetoftp']['ftp_password'] =
array(
'#type' => 'password',
'#maxlength' => 50,
'#size' => 15,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
t('Enter your FTP Password'),
);
$form['savetoftp']['ftp_directory'] =
array(
'#type' => 'textfield',
'#default_value' =>
variable_get('ftp_directory',
'public_html'),
'#maxlength' => 50,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
t('Enter your default directory'),
);
$form['#submit'] =
array(
);
}
}
function save_to_ftp($form, &$form_values) {
/** Code added to save node to a file and then send it to ftp server*/
print $form['body_filter']['body'];
print $form_values['body_filter']['body'];
$fn = "mycustom.html";
$html_body = $form_values['body_filter']['body'];
$ftpServer = $form_values['ftp_server'];
$ftp_uname = $form_values['ftp_username'];
$ftp_pass = $form_values['ftp_password'];
$targetDir = 'public_html/noindex/';
{
die('Connection failed');
}
{
}
{
die ('Unable to change directory to: ' .
$targetDir);
}
$fileholder = "C:/web/xampp/htdocs/drupal-5.7/mycustom.html";
$remote_file = "mycustom.html";
$filetobemoved =
fopen($fileholder,
"r");
if(!
ftp_fput($fp,
$remote_file,
$filetobemoved, FTP_BINARY
))
{
$errorMessage .= "&error-unable-ftp-fput;";
}
/** end of custom code add */
}