Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session variable doesn't seem to pass 1

Status
Not open for further replies.

whoknows361

Technical User
Sep 22, 2005
228
US
OK, I have been working on this - with some help - so thanks very much.. Here's the deal:
I am using a form in flash which a user clicks a button and a file is chosen and uploaded using the following php file "upload.php" - (notice the session variable)
Code:
<?

session_start();
// store session data
$_SESSION['myname']=$_FILES['Filedata']['name'];

//move the uploaded file
$file = "./files/".$_FILES['Filedata']['name'];
move_uploaded_file($_FILES['Filedata']['tmp_name'], $file);
chmod("./files/".$_FILES['Filedata']['name'], 0777);


?>

what this does is upload the file to the "files" directory - now this works perfectly... next in the flash file the user fills out a form and clicks the send email button - which calls the following php page "sendmail.php" - again
notice how I used the session variable:
Code:
<?
require("class.phpmailer.php");

$s_message = $_POST['sender_message'];    
$s_mail = $_POST['sender_mail']; 
$s_webpage = $_POST['sender_webpage'];  
$s_title = $_POST['sender_title'];
$s_image = $_SESSION['myname'];
$mail = new PHPMailer();


$mail->From     = $s_mail;
$mail->FromName = $s_mail;
$mail->AddAddress("logoskreations@yahoo.com","Jonathan"); 
$mail->AddReplyTo("logoskreations@yahoo.com","Jonathan");

$mail->WordWrap = 50;                              // set word wrap
$mail->AddAttachment($s_image);      // attachment
$mail->IsHTML(true);                               // send as HTML

$mail->Subject  =  "you have received an image from Chongaton.com";
$mail->Body     =  "users webpage is: $s_webpage.    users title is: $s_title.    users email is: $s_mail.    users message is: $s_message";
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

?>

Now - I am sure the flash code is correct. the image file uploads correctly & the email is sent and has all the right fields displayed - except that it does not contain the attachment. So it is clear that the session variable is not passing from the first php file to the second php file. Am I doing this correctly? If not, what are my options. Thanks in advance.

Jonathan
 
you need to start the session in the second script. session variables are not available until after you have made a call to session_start().


as previously posted, remember to set the umask to zero before doing a chmod to 0777
 
I included the
session_start();
call on the second script - however received the same result.
Thanks for the tip re: umask - will do.

Any other ideas how to make sure the session variable works.
It is ok that these php scripts are two different files right?

not sure how to make this work
 
i notice that you have not assigned the PATH to the session variable, just the name of the file.

you need to supply a complete reference to phpmailer. i.e. both the path and the filename, so that phpmailer will know where to find the file.

so the easiest solution is to edit the first script thus
Code:
<?

session_start();
// store session data


//move the uploaded file
//note use of realpath to obtain the ABSOLUTE path.  this is because the next script may not be at the same directory point
$file = realpath("./files/");
$file = $file . $_FILES['Filedata']['name'];  //now add the file name

//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], $file);

//set the umask to zero and capture the cur value to reset later
$u = umask(0);
//reset the file mode
chmod($file, 0777);
//reset umask to where it was
umask ($u);
//assign the path and filename to a session variable

$_SESSION['myname']= $file;

//if you are using header redirects to change the browser location, uncomment the next line.  it forces the session to save itself, so avoiding race conditions.
//session_write_close();
?>
 
jpadie - that is perfect - it does exactly what I want it to now. Thanks so much for your help.
Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top