<?
/*
   File name         : upload.php
   Version           : 1.1.0
   Last Modified By  : Umut Gokbayrak
   e-mail            : umut@trlinux.com
   Purpose           : Uploads attachments to a temporary disk place on the server.
   Last modified     : 11 Sep 2000
*/

include ("includes/global.inc");
session_start();

$attached=$_REQUEST["attached"];
$mbox_id=$_REQUEST["mbox_id"];
$post_act=$_REQUEST["post_act"];
$to=$_REQUEST["to"];
$cc=$_REQUEST["cc"];
$bcc=$_REQUEST["bcc"];
$subject=$_REQUEST["subject"];
$msgbody=$_REQUEST["msgbody"];
$userfile=$_FILES["userfile"]['tmp_name'];
$userfile_name=$_FILES["userfile"]['name'];
$ID=addslashes($_SESSION["ID"]);

// ID comparison between logged hash and session. If they are both the same, let the user to go on...
$dbq = $db->execute("select user_id,username,password from tblUsers where hash = '$ID'");
$user_id = $dbq->fields['user_id'];
$username = $dbq->fields['username'];
$password = $dbq->fields['password'];
$dbq->close();

if (($user_id == "") || (strlen($ID)==0)){
  Header("Location: index.php?error_id=1");
} else {
  // Saving the message body to a temporary file.
  $dosyaadi = "msgbody.txt";
  $fp = fopen($attach_directory . $ID . "#####" . "msgbody.txt", "w+");
  if ($fp) {
    $sonuc = fputs($fp, $msgbody);
    fclose($fp);
  } //end if


  if(copy($userfile, $attach_directory . $ID . "######" . $userfile_name)) {
    Header("Location: attachments.php?to=$to&cc=$cc&bcc=$bcc&subject=$subject&attached=1&mbox_id=$mbox_id&post_act=$post_act");
  } else {
    echo "&nbsp;<p>&nbsp;<p><div align='center'><h2>$text90</h2><p>";
    echo "<a href='attachments.php?to=$to&cc=$cc&bcc=$bcc&subject=$subject&attached=1'>$text47</a></div>\n";
  } // end if
}

?>
