Matthew Padgett
May 27th, 2008, 10:48 AM
hello.
Does this AS or PHP contain any errors? as I'm not getting the mail. I have taken out my email address, but even when it's in, the mail isn't sent back.
I'm also having a lot of 'invalid file' error messages when trying to upload jpegs... I don't know why.
Here i'll post my AS.
//Imports
import mx.utils.Delegate;
import mx.controls.ProgressBar;
import flash.net.FileReference;
import mx.transitions.Tween;
import mx.transitions.easing.*;
//class attachmentForm
class attachmentForm extends MovieClip {
//declarations
private var textMessage:TextField;
private var progressBar:ProgressBar;
private var button1:Button;
private var button2:Button;
private var _fileRef:FileReference;
private var errorPop:MovieClip;
private var mailForm:MovieClip;
private var nome:TextField;
private var oggetto:TextField;
private var email:TextField;
private var nazione:TextField;
private var messaggio:TextField;
private var traceBox:TextField;
private var URL:String = "uploadandsend.php";
//Constructor
public function attachmentForm() {
super();
}
//onLoad
private function onLoad():Void {
this.errorPop.progressBar.mode = "manual";
this.button1.onPress = Delegate.create(this, this.browse);
this._fileRef = new FileReference();
this._fileRef.addListener(this);
}
//Button events
private function browse():Void {
this.errorPop.progressBar.setProgress(0, 100);
var success:Boolean;
//open OS window and specify a description for each group and the file types allowed in that group
success = this._fileRef.browse([{description:'All Files (*.*)', extension:'*.*'}]);
//examples of usage
//success = this._fileRef.browse([{description: "All Formats (*.jpg,*.gif,*.png,*.swf)", extension: "*.jpg;*.gif;*.png;*.swf", macType: "jpg;JPEG;jp2_;GIFF;SWFL"},
//{description: "All Image Formats (*.jpg,*.gif,*.png)", extension: "*.jpg;*.gif;*.png", macType: "JPEG;jp2_;GIFF"},
//{description: "Flash Movies (*.swf)", extension: "*.swf", macType: "SWFL"}]);
// success = this._fileRef.browse([{description:'All Files (*.*)', extension:'*.*'}]);
// success = this._fileRef.browse([{description:'All Formats (*.jpg;*jpeg;*JPG;*JPEG;*gif;*GIF;*.pdf;*.doc;*.tx t)', extension:'*.jpg;*jpeg;*JPG;*JPEG;*gif;*GIF;*.pdf; *.doc;*.txt", macType:"jpg;JPEG;jp2_;GIFF;PDF;DOC;TXT'}]);
//if the OS window failed to open
if (success == false) {
errorPopup("error", "Can't open theOS browse windows");
}
}
//Popup for messages and errors
private function errorPopup(type:String, echo:String):Void {
this.errorPop.textMessage.text = echo;
switch (type) {
case "error" :
this.errorPop.progressBar._visible = false;
this.errorPop.gotoAndPlay("on");
break;
case "message" :
this.errorPop.progressBar._visible = false;
this.errorPop.gotoAndStop("on");
break;
case "progress" :
this.errorPop.progressBar._visible = true;
this.errorPop.gotoAndStop("on");
break;
}
//shows the popup
var popTweenIn:Tween = new Tween(this.errorPop, "_alpha", Regular.easeOut, 0, 100, .5, true);
}
//Upload
private function upload(variables:String):Void {
var success:Boolean;
success = this._fileRef.upload(URL+variables);
if (success == false) {
errorPopup("error", "Problems during file Upload");
}
}
//FileReference events
private function onSelect(fileRef:FileReference):Void {
this.textMessage.text = fileRef.name;
}
private function onOpen(fileRef:FileReference):Void {
errorPopup("progress", "File upload is in progress");
}
private function onProgress(fileRef:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
this.errorPop.progressBar.setProgress(bytesLoaded, bytesTotal);
}
private function onComplete(fileRef:FileReference):Void {
errorPopup("progress", "File upload was completed");
this.errorPop.progressBar.setProgress(100, 100);
this.errorPop.gotoAndPlay("on");
this.mailForm.gotoAndPlay("done");
}
private function onCancel():Void {
errorPopup("error", "Browse window closed by the user");
}
private function onHTTPError(fileRef:FileReference, error:Number):Void {
errorPopup("error", "File upload error on: "+fileRef.name+"\n code: "+error);
}
private function onIOError(fileRef:FileReference):Void {
errorPopup("error", "File is invalid: "+fileRef.name);
}
private function onSecurityError(fileRef:FileReference, error_str:String):Void {
errorPopup("error", "onSecurityError: "+fileRef.name+" error : "+error_str);
}
}
and here I'll add my PHP code.
//utilities and functions
//date and time from the server
$date = date("m/d/Y H:i:s");
//IP Address
if ($REMOTE_ADDR == "") $ip = "no ip";
else $ip = getHostByAddr($REMOTE_ADDR);
//stips filename extension
function filext($filename)
{
$path_info = pathinfo($filename);
return $path_info['extension'];
}
////////////////////////////////////////////////////
//configuration
$sitename = "my site name"; // website name
$email_to = "my email address"; // mail recipient
$email_subject = $subject; // email subject (here you can ovverride the one written in the form)
//headers
$headers = "De: ".$email;
//email message
$email_message = "Un visiteur sur $sitename a envoyé les infos suivants: <br/><br/>
Nom: $name <br/>
Ville: $town <br/>
Sujet: $subject <br/>
Email: $email <br/>
Téléphone: $phone <br/><br/>
Message: <br/>
$message <br/><br/><br/>
Info Utilisateur:<br/>
Hostname: $ip<br/>
IP: $REMOTE_ADDR<br/>
Date/ Heure: $date";
//path to temporary storage
$storage = 'uploadedFiles';
//path name of file for storage
$uploadfile = "$storage/" . basename( $_FILES['Filedata']['name'] );
//if the file is moved successfully
if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
echo( '1 ' . $_FILES['Filedata']['name']);
$fileatt = $uploadfile; // Path to the file
$fileatt_type = mime_content_type($fileatt); // Mime File Type
$fileatt_name = $email."_attached.".filext($fileatt); // Filename that will be used for the file as the attachment
//random number function
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$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_message . "\n\n";
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$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";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
// send email
$ok = @mail($email_to, $email_subject, $email_message, $headers);
//check result
if($ok) {
//erase the uploade temporary file
unlink($uploadfile);
} else {
die("ko");
}
//file failed to move
}else{
echo( '0');
}
?>
I bought this 'uploader' from flashnet and i have already corrected a few errors in the AS but now I'm at a loss as to what could be the problems.
any help would be nice.
Does this AS or PHP contain any errors? as I'm not getting the mail. I have taken out my email address, but even when it's in, the mail isn't sent back.
I'm also having a lot of 'invalid file' error messages when trying to upload jpegs... I don't know why.
Here i'll post my AS.
//Imports
import mx.utils.Delegate;
import mx.controls.ProgressBar;
import flash.net.FileReference;
import mx.transitions.Tween;
import mx.transitions.easing.*;
//class attachmentForm
class attachmentForm extends MovieClip {
//declarations
private var textMessage:TextField;
private var progressBar:ProgressBar;
private var button1:Button;
private var button2:Button;
private var _fileRef:FileReference;
private var errorPop:MovieClip;
private var mailForm:MovieClip;
private var nome:TextField;
private var oggetto:TextField;
private var email:TextField;
private var nazione:TextField;
private var messaggio:TextField;
private var traceBox:TextField;
private var URL:String = "uploadandsend.php";
//Constructor
public function attachmentForm() {
super();
}
//onLoad
private function onLoad():Void {
this.errorPop.progressBar.mode = "manual";
this.button1.onPress = Delegate.create(this, this.browse);
this._fileRef = new FileReference();
this._fileRef.addListener(this);
}
//Button events
private function browse():Void {
this.errorPop.progressBar.setProgress(0, 100);
var success:Boolean;
//open OS window and specify a description for each group and the file types allowed in that group
success = this._fileRef.browse([{description:'All Files (*.*)', extension:'*.*'}]);
//examples of usage
//success = this._fileRef.browse([{description: "All Formats (*.jpg,*.gif,*.png,*.swf)", extension: "*.jpg;*.gif;*.png;*.swf", macType: "jpg;JPEG;jp2_;GIFF;SWFL"},
//{description: "All Image Formats (*.jpg,*.gif,*.png)", extension: "*.jpg;*.gif;*.png", macType: "JPEG;jp2_;GIFF"},
//{description: "Flash Movies (*.swf)", extension: "*.swf", macType: "SWFL"}]);
// success = this._fileRef.browse([{description:'All Files (*.*)', extension:'*.*'}]);
// success = this._fileRef.browse([{description:'All Formats (*.jpg;*jpeg;*JPG;*JPEG;*gif;*GIF;*.pdf;*.doc;*.tx t)', extension:'*.jpg;*jpeg;*JPG;*JPEG;*gif;*GIF;*.pdf; *.doc;*.txt", macType:"jpg;JPEG;jp2_;GIFF;PDF;DOC;TXT'}]);
//if the OS window failed to open
if (success == false) {
errorPopup("error", "Can't open theOS browse windows");
}
}
//Popup for messages and errors
private function errorPopup(type:String, echo:String):Void {
this.errorPop.textMessage.text = echo;
switch (type) {
case "error" :
this.errorPop.progressBar._visible = false;
this.errorPop.gotoAndPlay("on");
break;
case "message" :
this.errorPop.progressBar._visible = false;
this.errorPop.gotoAndStop("on");
break;
case "progress" :
this.errorPop.progressBar._visible = true;
this.errorPop.gotoAndStop("on");
break;
}
//shows the popup
var popTweenIn:Tween = new Tween(this.errorPop, "_alpha", Regular.easeOut, 0, 100, .5, true);
}
//Upload
private function upload(variables:String):Void {
var success:Boolean;
success = this._fileRef.upload(URL+variables);
if (success == false) {
errorPopup("error", "Problems during file Upload");
}
}
//FileReference events
private function onSelect(fileRef:FileReference):Void {
this.textMessage.text = fileRef.name;
}
private function onOpen(fileRef:FileReference):Void {
errorPopup("progress", "File upload is in progress");
}
private function onProgress(fileRef:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
this.errorPop.progressBar.setProgress(bytesLoaded, bytesTotal);
}
private function onComplete(fileRef:FileReference):Void {
errorPopup("progress", "File upload was completed");
this.errorPop.progressBar.setProgress(100, 100);
this.errorPop.gotoAndPlay("on");
this.mailForm.gotoAndPlay("done");
}
private function onCancel():Void {
errorPopup("error", "Browse window closed by the user");
}
private function onHTTPError(fileRef:FileReference, error:Number):Void {
errorPopup("error", "File upload error on: "+fileRef.name+"\n code: "+error);
}
private function onIOError(fileRef:FileReference):Void {
errorPopup("error", "File is invalid: "+fileRef.name);
}
private function onSecurityError(fileRef:FileReference, error_str:String):Void {
errorPopup("error", "onSecurityError: "+fileRef.name+" error : "+error_str);
}
}
and here I'll add my PHP code.
//utilities and functions
//date and time from the server
$date = date("m/d/Y H:i:s");
//IP Address
if ($REMOTE_ADDR == "") $ip = "no ip";
else $ip = getHostByAddr($REMOTE_ADDR);
//stips filename extension
function filext($filename)
{
$path_info = pathinfo($filename);
return $path_info['extension'];
}
////////////////////////////////////////////////////
//configuration
$sitename = "my site name"; // website name
$email_to = "my email address"; // mail recipient
$email_subject = $subject; // email subject (here you can ovverride the one written in the form)
//headers
$headers = "De: ".$email;
//email message
$email_message = "Un visiteur sur $sitename a envoyé les infos suivants: <br/><br/>
Nom: $name <br/>
Ville: $town <br/>
Sujet: $subject <br/>
Email: $email <br/>
Téléphone: $phone <br/><br/>
Message: <br/>
$message <br/><br/><br/>
Info Utilisateur:<br/>
Hostname: $ip<br/>
IP: $REMOTE_ADDR<br/>
Date/ Heure: $date";
//path to temporary storage
$storage = 'uploadedFiles';
//path name of file for storage
$uploadfile = "$storage/" . basename( $_FILES['Filedata']['name'] );
//if the file is moved successfully
if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
echo( '1 ' . $_FILES['Filedata']['name']);
$fileatt = $uploadfile; // Path to the file
$fileatt_type = mime_content_type($fileatt); // Mime File Type
$fileatt_name = $email."_attached.".filext($fileatt); // Filename that will be used for the file as the attachment
//random number function
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$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_message . "\n\n";
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$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";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
// send email
$ok = @mail($email_to, $email_subject, $email_message, $headers);
//check result
if($ok) {
//erase the uploade temporary file
unlink($uploadfile);
} else {
die("ko");
}
//file failed to move
}else{
echo( '0');
}
?>
I bought this 'uploader' from flashnet and i have already corrected a few errors in the AS but now I'm at a loss as to what could be the problems.
any help would be nice.