Pogledajte određenu poruku
Staro 24. 06. 2008.   #1
R. S.
novi član
 
Datum učlanjenja: 24.06.2008
Poruke: 3
Hvala: 0
0 "Hvala" u 0 poruka
R. S. is on a distinguished road
Question Slanje fajlova putem formulara na mail?

Zamoliću za pomoć. Problem je sledeći: putem formulara sa HTML stranice treba proslediti i fajl - .doc ili .pdf na odredjenu e-mail adresu (PHP skript koji se poziva i prosledjuje vrednosti radi, ali ne i deo za slanje fajlova)...

Obzirom da sam početnik i da danima ne nalazim rešenje (koje naravno hitno treba) još jednom apelujem na neku dobru dušu da mi pomogne

Kod je sledeći:

HTML kôd:
<?
		include 'include/connect.db.inc.php';
				
		
		$fname = $_POST['name_first'];
		$lname = $_POST['name_last'];
		$ad = $_POST['address'];
		$email = $_POST['mail'];

		
		$to = "my.gml.rs@gmail.com"; 
		$subject = "Application: ".$fname." ".$lname;
	
	    	$content .= "<b><u>APPLICATION</u></b><br /><br />";
	        $content .= "<b>First Name:</b> ".$fname." <br />";
	        $content .= "<b>Last Name:</b> ".$lname." <br />";
	        $content .= "<b>Address:</b> ".$ad." <br />";
	        $content .= "<b>E-mail:</b> ".$email." <br /><br />";


	         // 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'];

	        // here we'll hard code a text message
	        // again, in reality, you'll normally get this from the form submission

                // if the upload succeded, the file will exist
   	       if ((file_exists($tmp_name) && $size < 5000000 ) || $$tmp_name==""){

      	        // 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));
		
		}}



          // now we'll build the message headers
         $header = "From: Web Formular \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/html; charset=\"utf-8\"\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 .= "Content-Type: ".$type."\r\n" . 
             " name=\"".$name."\"\r\n" . 
             "Content-Transfer-Encoding: base64\r\n" . 
             "Content-Disposition: attachment;\r\n" . 
             " filename=\"".$name."\"\r\n\r\n" . 
             $data."\r\n" . 
             "--".$mime_boundary."\r\n";

		
			
		mail($to, $subject, $content, $message, $header);
		
		echo("<script>document.location=\"formular.htm\";</script>");
		?>
R. S. je offline   Odgovorite uz citat