Skip to content

Instantly share code, notes, and snippets.

@insidenothing
Created October 19, 2010 13:51
Show Gist options
  • Save insidenothing/634216 to your computer and use it in GitHub Desktop.
Save insidenothing/634216 to your computer and use it in GitHub Desktop.
function printAD($id,$ip){
$r=@mysql_query("select LiveAdHTML from schedule_items where schedule_id = '$id'");
$d=mysql_fetch_array($r,MYSQL_ASSOC);
$myFile = "/data/auction/adMaster/$id.html";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $d[LiveAdHTML]);
fclose($fh);
passthru('/usr/local/bin/html2ps /data/auction/adMaster/'.$id.'.html > /data/auction/adMaster/'.$id.'.ps');
$file = /data/auction/adMaster/$id.'.ps';
$remote_file = $id.'.ps';
if ($conn_id = ftp_connect($ip)) {
//echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else {
//echo "Couldn't change directory\n";
mail('insidenothing@gmail.com','PRINTER CONNECT','Couldn\'t connect');
error_log(date('r')." $ip WARNING: Couldn't connect. \n", 3, '/logs/printer.log');
return 'fail';
}
$login_result = ftp_login($conn_id, 'alpha', 'beta');
ftp_pasv($conn_id, true);
if (ftp_chdir($conn_id, "PORT1")) {
//echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else {
//echo "Couldn't change directory\n";
mail('insidenothing@gmail.com','PRINTER CHDIR','Couldn\'t change directory');
error_log(date('r')." $ip WARNING: Couldn't change ftp directory for burson edited ad $id. \n", 3, '/logs/printer.log');
}
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
//echo "successfully uploaded $file\n";
$last_line = system('rm -f '.$id.'.ps', $retval);
$last_line = system('rm -f '.$id.'.rtf', $retval);
$last_line = system('rm -f '.$id.'.html', $retval);
error_log(date('r')." $ip NOTICE: Burson edited ad $id printed successfully. \n", 3, '/logs/printer.log');
} else {
//echo "There was a problem while uploading $file\n";
mail('insidenothing@gmail.com','AI Break: FTP PUT','There was a problem while uploading '.$file);
error_log(date('r')." $ip ERROR: There was a problem while uploading edited ad $id. \n", 3, '/logs/printer.log');
return 'fail';
}
ftp_close($conn_id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment