Jump to content

Recommended Posts

Hello

I have googled for an email upload form, i found a code that i can undersdtand, I tried to modify it so only .ask extension is allowed and the file doesn't exceed 200KB (line 39!)

 

I uploaded .ask file and it was sent successfullt (as I want), I also tried to upload other types of files and it didn't send it (as I want)

but the form didn't inform the user that the file was NOT send because it is of diffrent extension or file size.

 

I just want to add this echo statment please

 

thanks

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>E-mail with Attachment</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
   if ($_SERVER['REQUEST_METHOD']=="POST"){

	$size = $_FILES['filename']['size'];
	$name = $_FILES['filename']['name'];
	$array = explode( '.' , $name);

   // we'll begin by assigning the To address and message subject
   $to="malekface@hotmail.com";

   $subject="E-mail with attachment";

   // get the sender's name and email address
   // we'll just plug them a variable to be used later
   $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

   // generate a random string to be used as the boundary marker
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

   // store the file information to variables for easier access
   $tmp_name = $_FILES['filename']['tmp_name'];
   $type = $_FILES['filename']['type'];
   $name = $_FILES['filename']['name']; echo "name: $name<br>";
   $size = $_FILES['filename']['size'];

   // here we'll hard code a text message
   // again, in reality, you'll normally get this from the form submission
   $message = "A New File from GSCLOnline,org: $name";

   // if the upload succeded, the file will exist
   if (file_exists($tmp_name) && $array[1] == 'ask' && $size < 200 ){

      // check to make sure that it is an uploaded file and not a system file
      if(is_uploaded_file($tmp_name) ){

         // open the file for a binary read
         $file = fopen($tmp_name,'rb');

         // read the file content into a variable
         $data = fread($file,filesize($tmp_name));

         // close the file
         fclose($file);

         // now we encode it and split it into acceptable length lines
         $data = chunk_split(base64_encode($data));
     }
echo "Credits are decreased<br>";

      // now we'll build the message headers
      $headers = "From: $from\r\n" .
         "MIME-Version: 1.0\r\n" .
         "Content-Type: multipart/mixed;\r\n" .
         " boundary=\"{$mime_boundary}\"";

      // next, we'll build the message body
      // note that we insert two dashes in front of the
      // MIME boundary when we use it
      $message = "This is a multi-part message in MIME format.\n\n" .
         "--{$mime_boundary}\n" .
         "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
         "Content-Transfer-Encoding: 7bit\n\n" .
         $message . "\n\n";

      // now we'll insert a boundary to indicate we're starting the attachment
      // we have to specify the content type, file name, and disposition as
      // an attachment, then add the file content and set another boundary to
      // indicate that the end of the file has been reached
      $message .= "--{$mime_boundary}\n" .
         "Content-Type: {$type};\n" .
         " name=\"{$name}\"\n" .
         //"Content-Disposition: attachment;\n" .
         //" filename=\"{$fileatt_name}\"\n" .
         "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n" .
         "--{$mime_boundary}--\n";

      // now we just send the message
      if (@mail($to, $subject, $message, $headers))
         echo "Message Sent";
      else
         echo "Failed to send";
   }
} else {
?>
<p>Send an e-mail with an attachment:</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" 
   enctype="multipart/form-data" name="form1">
   <p>From name: <input type="text" name="fromname"></p>
   <p>From e-mail: <input type="text" name="fromemail"></p>
   <p>File: <input type="file" name="filename"></p>
   <p><input type="submit" name="Submit" value="Submit"></p>
</form>
<?php } ?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/111210-need-echo-statment/
Share on other sites

Try changing:

      // now we just send the message
      if (@mail($to, $subject, $message, $headers))
         echo "Message Sent";
      else
         echo "Failed to send";

 

to this:


if ($type == 'ask') {

// Place any thing here if you want to show what happens if its accepted

} else {

// Place any thing here if you want to show what happens if its NOT accepted

echo "You did not upload a .ask file, Please try again.";
}

      // now we just send the message
      if (@mail($to, $subject, $message, $headers))
         echo "Message Sent";
      else
         echo "Failed to send";

 

Link to comment
https://forums.phpfreaks.com/topic/111210-need-echo-statment/#findComment-570862
Share on other sites

Try changing:

      // now we just send the message
      if (@mail($to, $subject, $message, $headers))
         echo "Message Sent";
      else
         echo "Failed to send";

 

to this:


if ($type == 'ask') {

// Place any thing here if you want to show what happens if its accepted

} else {

// Place any thing here if you want to show what happens if its NOT accepted

echo "You did not upload a .ask file, Please try again.";
}

      // now we just send the message
      if (@mail($to, $subject, $message, $headers))
         echo "Message Sent";
      else
         echo "Failed to send";

 

You're code should be:

if ($type == 'ask') {

// Place any thing here if you want to show what happens if its accepted

      // now we just send the message
      if (@mail($to, $subject, $message, $headers))
         echo "Message Sent";
      else
         echo "Failed to send";

} else {

// Place any thing here if you want to show what happens if its NOT accepted

echo "You did not upload a .ask file, Please try again.";
}

I presume.

Link to comment
https://forums.phpfreaks.com/topic/111210-need-echo-statment/#findComment-570865
Share on other sites

Hi thanks for u all

 

I used papaface's code

if ($array[1] == 'ask') {

 

echo "it is working";

 

      // now we just send the message

      if (@mail($to, $subject, $message, $headers))

        echo "Message Sent";

      else

        echo "Failed to send";

 

} else {

 

echo "You did not upload a .ask file, Please try again.";

}

 

When the file is .ask it printing: it is working, while it is NOT, it is NOt printing anything?!

very stange, why?

Link to comment
https://forums.phpfreaks.com/topic/111210-need-echo-statment/#findComment-571037
Share on other sites

Hi again

 

I need to add smthg to the form. When the .ask file is accepted. the code should make some DB process, but the varaible that I passed throught url before is not appearing in the (if accepted scope).

When I first open this form page, I echoed the varaiable and i can see it, but when i press submit and the file is .ask, the echo doesn't show me the variable (cuz it is empty) and the DB code is not applied.

 

kindly help

Link to comment
https://forums.phpfreaks.com/topic/111210-need-echo-statment/#findComment-571349
Share on other sites

Hi

I edited the form to this:

 

?>

<p>Upload your ask file. Please keep youf filename as is.</p>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"

  enctype="multipart/form-data" name="form1">

  <p>File: <input type="file" name="filename"></p>

  <input type="hidden" name="user" value="$user">

  <p><input type="submit" name="Submit" value="Submit"></p>

</form>

<?php } ?>

 

and I added this get in the begining:

$user= $_GET['user'];

echo "The User = $user";

 

When I first open the this form, i can see the ablove lin echoed user name!

when submitted, the username doesn't appear.

Link to comment
https://forums.phpfreaks.com/topic/111210-need-echo-statment/#findComment-571371
Share on other sites

I don't any problem now posting the user anymore.

 

I made some modifications to the code. It is logiually working now, If the user (after quering the DB) doens't have any credits, the file is NOT sent, the same idea if the file is NOT .ask.

If the user has credits and the file is .ask, the file is sent and i got it in my inbox. other DB process traces show that everything is 100% correct.

When the file is sent, the code prints : File sent (which is correct)

 

When it is NOT sent, i need to inform the user that the file is not .ask or he doesn't have enough credits

Where do I add this echo?

thanks

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Send Your ask File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include('../CMS/global.inc.php');

   if ($_SERVER['REQUEST_METHOD']=="POST"){

	$size = $_FILES['filename']['size'];
	$name = $_FILES['filename']['name'];
	$array = explode( '.' , $name);
	$user = $_POST['user'];
	$date = date("y-m-d");

   // we'll begin by assigning the To address and message subject
   $to="malekface@hotmail.com";
   $subject="File to unlock";

   // get the sender's name and email address
   // we'll just plug them a variable to be used later
   //$from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";
   $from = "GSCL";

   // generate a random string to be used as the boundary marker
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

   // store the file information to variables for easier access
   $tmp_name = $_FILES['filename']['tmp_name'];
   $type = $_FILES['filename']['type'];
   $name = $_FILES['filename']['name'];
   $size = $_FILES['filename']['size'];
   
   		//check if the user has credits before sending a file
$query = "SELECT * FROM `credits` WHERE `user` = '$user' ";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

   // here we'll hard code a text message
   // again, in reality, you'll normally get this from the form submission
   $message = "A New File from GSCLOnline.org: $name";

   // if the upload succeded, the file will exist
   if (file_exists($tmp_name) && $array[1] == 'ask' && $size < 200  && $row[num]>=1){

      // check to make sure that it is an uploaded file and not a system file
      if(is_uploaded_file($tmp_name) ){

         // open the file for a binary read
         $file = fopen($tmp_name,'rb');

         // read the file content into a variable
         $data = fread($file,filesize($tmp_name));

         // close the file
         fclose($file);

         // now we encode it and split it into acceptable length lines
         $data = chunk_split(base64_encode($data));

$query=" INSERT INTO `uploaded` ( `user` , `sentfile` , `date` , `received`) VALUES
('$user', '$name', '$date', 'N')";
$query_result = mysql_query ($query, $dbh);

$query = " UPDATE `credits` SET `num` = num-1 WHERE `user` = '$user' ";
$result = mysql_query($query);


     }//end if uploaded file

      // now we'll build the message headers
      $headers = "From: $from\r\n" .
         "MIME-Version: 1.0\r\n" .
         "Content-Type: multipart/mixed;\r\n" .
         " boundary=\"{$mime_boundary}\"";

      // next, we'll build the message body
      // note that we insert two dashes in front of the
      // MIME boundary when we use it
      $message = "This is a multi-part message in MIME format.\n\n" .
         "--{$mime_boundary}\n" .
         "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
         "Content-Transfer-Encoding: 7bit\n\n" .
         $message . "\n\n";

      // now we'll insert a boundary to indicate we're starting the attachment
      // we have to specify the content type, file name, and disposition as
      // an attachment, then add the file content and set another boundary to
      // indicate that the end of the file has been reached
      $message .= "--{$mime_boundary}\n" .
         "Content-Type: {$type};\n" .
         " name=\"{$name}\"\n" .
         //"Content-Disposition: attachment;\n" .
         //" filename=\"{$fileatt_name}\"\n" .
         "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n" .
         "--{$mime_boundary}--\n";

      // now we just send the message
      if (@mail($to, $subject, $message, $headers))
         echo "file sent! ";
      else
         echo "Failed to send";
   }
} else {
//echo "File was Not sent, you either don't have enough credits or the file is not .ask";
?>

<p>Upload your ask file. Please keep your filename as is.</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" 
   enctype="multipart/form-data" name="form1">
   <p>File: <input type="file" name="filename"></p>
<? $user= $_GET['user'];  echo "Usr name in get = $user"; echo" <input type='hidden' name='user' value='$user'>"; ?>
   <p><input type="submit" name="Submit" value="Submit"></p>
</form>
<?php } ?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/111210-need-echo-statment/#findComment-572103
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.