code
<?php
// begin our session
session_start();
$check=0;
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
//close the zip -- done!
$zip->close();
//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}//end function
//start send mail
$myFile1 = $_FILES['txt_file1']; // This will make an array out of the file information that was stored.
$file1 = $myFile1['tmp_name']; //Converts the array into a new string containing the path name on the server where your file is.
$myFileName1 = basename($_FILES['txt_file1']['name']); //Retrieve filename out of file path
$destination_file1 = "./" .$myFileName1 ;
if($myFileName1 == ''){
echo "<script language=\"javascript\" type=\"text/javascript\">
alert('Please enter your attached file.');
window.location = \"web_mform3.php\";
</script>";
}
$myFile2 = $_FILES['txt_file2']; // This will make an array out of the file information that was stored.
$file2 = $myFile2['tmp_name']; //Converts the array into a new string containing the path name on the server where your file is.
$myFileName2 = basename($_FILES['txt_file2']['name']); //Retrieve filename out of file path
$destination_file2 = "./" .$myFileName2 ;
$myFile3 = $_FILES['txt_file3']; // This will make an array out of the file information that was stored.
$file3 = $myFile3['tmp_name']; //Converts the array into a new string containing the path name on the server where your file is.
$myFileName3 = basename($_FILES['txt_file3']['name']); //Retrieve filename out of file path
$destination_file3 = "./" .$myFileName3 ;
if (!mysqli_query($conn,$sql))
{
die('Error: ' . mysqli_error($conn));
}
mysqli_close($conn);
//end write data
#"/developers/uploadftp/aditya/".$myFileName; //where you want to throw the file on the webserver (relative to your login dir)
// connection settings
$ftp_server = "f"; //address of ftp server.
$ftp_user_name = ""; // Username
$ftp_user_pass = ""; // Password
$conn_id = ftp_connect($ftp_server) or die("<span style='color:#FF0000'><h2>Couldn't connect to $ftp_server</h2></span>"); // set up basic connection
#print_r($conn_id);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<span style='color:#FF0000'><h2>You do not have access to this ftp server!</h2></span>"); // login with username and password, or give invalid user message
if ((!$conn_id) || (!$login_result)) { // check connection
// wont ever hit this, b/c of the die call on ftp_login
echo "<span style='color:#FF0000'><h2>FTP connection has failed! <br />";
echo "Attempted to connect to $ftp_server for user $ftp_user_name</h2></span>";
exit;
} else {
// echo "Connected to $ftp_server, for user $ftp_user_name <br />";
}
$upload = ftp_put($conn_id, $destination_file1, $file1, FTP_BINARY); // upload the file(1)
if (!$upload) { // check upload status
echo "<span style='color:#FF0000'><h2>FTP upload of $myFileName1 has failed!</h2></span> <br />";
} else {
echo "<span style='color:#339900'><h2>Uploading $myFileName1 Completed Successfully!</h2></span><br /><br />";
}
if($myFileName2 != ''){//if file2
$upload = ftp_put($conn_id, $destination_file2, $file2, FTP_BINARY); // upload the file(2)
if (!$upload) { // check upload status
echo "<span style='color:#FF0000'><h2>FTP upload of $myFileName2 has failed!</h2></span> <br />";
} else {
echo "<span style='color:#339900'><h2>Uploading $myFileName2 Completed Successfully!</h2></span><br /><br />";
}
}//end if file2
if($myFileName3 != ''){//if file3
$upload = ftp_put($conn_id, $destination_file3, $file3, FTP_BINARY); // upload the file(3)
if (!$upload) { // check upload status
echo "<span style='color:#FF0000'><h2>FTP upload of $myFileName3 has failed!</h2></span> <br />";
} else {
echo "<span style='color:#339900'><h2>Uploading $myFileName3 Completed Successfully!</h2></span><br /><br />";
}
}//end if file3
ftp_close($conn_id); // close the FTP stream
$file = 'C:\Inetpub\vhosts\wardmedic.com\ward_ftp\\'.$myFileName1;
$newfile = 'C:\Inetpub\vhosts\wardmedic.com\httpdocs\excel\\'.$myFileName1;
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}else{
unlink($file);
}
if($myFileName2 != ''){//if file2
$file = 'C:\Inetpub\vhosts\wardmedic.com\ward_ftp\\'.$myFileName2;
$newfile = 'C:\Inetpub\vhosts\wardmedic.com\httpdocs\excel\\'.$myFileName2;
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}else{
unlink($file);
}
}//end if file2
if($myFileName3 != ''){//if file3
$file = 'C:\Inetpub\vhosts\wardmedic.com\ward_ftp\\'.$myFileName3;
$newfile = 'C:\Inetpub\vhosts\wardmedic.com\httpdocs\excel\\'.$myFileName3;
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}else{
unlink($file);
}
}//end if file3
//if true, good; if false, zip creation failed
$zipfile = 'requisit_1_'.$date.'billNO'.$billNO.'.zip';
$billNO=$billNO+1;
$zip1=$zipfile;
$result = create_zip($files_to_zip,$zipfile);
//send mail first bill. : [email protected] , [email protected] , [email protected] , [email protected]
if(!$blacklist)
$email_to =$email_to."[email protected] , [email protected] , [email protected] , [email protected] , [email protected] "; // The email you are sending to (example)
else
$email_to =$email_to."[email protected] ";
$email_from = $_SESSION['login_name']; // The email you are sending from (example)
if($blacklist)
$email_subject = "This is BlackList customer !!! , ";
$email_subject = $email_subject." Sequencing Order in the attached file"; // The Subject of the email
$email_txt = "There is a new sequencing order from ".$_SESSION['login_name']." (Please find the attached file for new Sequencing Order.) ";
$email_txt = $email_txt." Tracking Type : ".$trackno." ";
$email_txt = $email_txt." Comments : ".$Comments." "; // Message that the email has in it
$fileatt = $zipfile; // Path to the file (example)
$fileatt_type = "application/zip"; // File Type
$fileatt_name = $zipfile; // Filename that will be used for the file as the attachment
//send mail second bill.
$email_to =$email_to."[email protected] "; // The email you are sending to (example)
$email_from = $_SESSION['login_name']; // The email you are sending from (example)
if($blacklist)
$email_subject = "This is BlackList customer , ";
$email_subject = $email_subject." Sequencing Order in the attached file"; // The Subject of the email
$email_txt = "There is a new sequencing order from ".$_SESSION['login_name']." (Please find the attached file for new Sequencing Order.) ";
$email_txt = $email_txt." Tracking Type : ".$trackno." ";
$email_txt = $email_txt." Comments : ".$Comments." "; // Message that the email has in it
$fileatt = $zipfile; // Path to the file (example)
$fileatt_type = "application/zip"; // File Type
$fileatt_name = $zipfile; // Filename that will be used for the file as the attachment
//if true, good; if false, zip creation failed
$zipfile = 'requisit_1_'.$date.'billNO'.$billNO.'.zip';
$billNO=$billNO+1;
$zip3=$zipfile;
$result = create_zip($files_to_zip,$zipfile);
//send mail third bill.
$email_to =$email_to."[email protected] "; // The email you are sending to (example)
$email_from = $_SESSION['login_name']; // The email you are sending from (example)
if($blacklist)
$email_subject = "This is BlackList customer , ";
$email_subject = $email_subject." Sequencing Order in the attached file"; // The Subject of the email
$email_txt = "There is a new sequencing order from ".$_SESSION['login_name']." (Please find the attached file for new Sequencing Order.) ";
$email_txt = $email_txt." Tracking Type : ".$trackno." ";
$email_txt = $email_txt." Comments : ".$Comments." "; // Message that the email has in it
$fileatt = $zipfile; // Path to the file (example)
$fileatt_type = "application/zip"; // File Type
$fileatt_name = $zipfile; // Filename that will be used for the file as the attachment
//if true, good; if false, zip creation failed
$zipfile = 'requisit_1_'.$date.'billNO'.$billNO.'.zip';
$billNO=$billNO+1;
$zip4=$zipfile;
$result = create_zip($files_to_zip,$zipfile);
//send mail
$email_to = "[email protected] "; // The email you are sending to (example)
$email_from = $_SESSION['login_name']; // The email you are sending from (example)
$email_subject = "Sequencing Order in the attached file"; // The Subject of the email
$email_txt = "There is a new sequencing order from ".$_SESSION['login_name']." (Please find the attached file for new Sequencing Order.) ";
$email_txt = $email_txt." Tracking Type : ".$trackno." ";
$email_txt = $email_txt." Comments : ".$Comments." "; // Message that the email has in it
$fileatt = $zipfile; // Path to the file (example)
$fileatt_type = "application/zip"; // File Type
$fileatt_name = $zipfile; // Filename that will be used for the file as the attachment
//if true, good; if false, zip creation failed
$zipfile = 'requisit_1_'.$date.'billNO'.$billNO.'.zip';
$billNO=$billNO+1;
$zip5=$zipfile;
$result = create_zip($files_to_zip,$zipfile);
$email_to="";
$email_subject="";
$blacklist=false;
//send mail
$email_to =$email_to."[email protected] "; // The email you are sending to (example)
$email_from = $_SESSION['login_name']; // The email you are sending from (example)
//echo"<br> '".$blacklist."'";
if($blacklist==true)
$email_subject="Black List mail!!! , ";
$email_subject =$email_subject."Sequencing Order in the attached file"; // The Subject of the email
$email_txt = "There is a new sequencing order from ".$_SESSION['login_name']." (Please find the attached file for new Sequencing Order.) ";
if($blacklist==true)
$email_txt=$email_txt."Black List mail!!! , ";
$email_txt = $email_txt." Tracking Type : ".$trackno." ";
$email_txt = $email_txt." Comments : ".$Comments." "; // Message that the email has in it
$fileatt = $zipfile; // Path to the file (example)
$fileatt_type = "application/zip"; // File Type
$fileatt_name = $zipfile; // Filename that will be used for the file as the attachment
$headers="From: $email_from"; // Who the email is from (example)
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
//------------------------------Test Attract all bills in one time email.
/*
$email_to = "[email protected] "; // The email you are sending to (example)
$email_from = $_SESSION['login_name']; // The email you are sending from (example)
$email_subject = "Test multi attracted file"; // The Subject of the email
$email_txt = "There is a new sequencing order from ".$_SESSION['login_name']." (Please find the attached file for new Sequencing Order.) ";
$email_txt = $email_txt." Tracking Type : ".$trackno." ";
$email_txt = $email_txt." Comments : ".$Comments." "; // Message that the email has in it
$fileatt_type = "application/zip"; // File Type
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $message, $headers);
if ($ok) {
echo "<br>Mail sent multi files attracted already.</br>";
} else {
echo "<br>Mail could not be sent multi files attracted.!</br>";
}
}
//send mail
$email_to = "[email protected] "; // The email you are sending to (example)
$email_from = $_SESSION['login_name']; // The email you are sending from (example)
$email_subject = "Multiple bills for a customer in one email , Sequencing Order in the attached file"; // The Subject of the email
$email_txt = "There is a new sequencing order from ".$_SESSION['login_name']." (Please find the attached file for new Sequencing Order.) ";
$email_txt = $email_txt." Tracking Type : ".$trackno." ";
$email_txt = $email_txt." Comments : ".$Comments." "; // Message that the email has in it
$fileatt = $zip1; // Path to the file (example)
$fileatt_type = "application/zip"; // File Type
$fileatt_name = $zip1; // Filename that will be used for the file as the attachment
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers="From: $email_from"; // Who the email is from (example)
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $email_txt;
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
if($check!=0)
{
echo "<script language=\"javascript\" type=\"text/javascript\">
alert('Your order complete!. Thank you for your cooperation.');
window.location = \"web_mmenu2.php\";
</script>";
}
else
{
echo "<script language=\"javascript\" type=\"text/javascript\">
alert('Your order complete!. Thank you for your cooperation.');
window.location = \"web_mform3_2.php\";
</script>";
}
}//End
?>