Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 914391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:42:39+00:00 2026-05-15T17:42:39+00:00

I created uploads folder on the server, and a file uploaded by a user

  • 0

I created “uploads” folder on the server, and a file uploaded by a user on the HTML form, gets into that folder fine.
Next, I try to retrieve it from that folder and attach it to an email, but this part doesn’t work.
Here is my PHP:

    <?php
$name = $_POST['name'];
$email = $_POST['email'];
$form_subject = $_POST['form_subject'];
$message = $_POST['message'];


//File upload

// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}   

//End of file upload


$ip=@$REMOTE_ADDR;
$date=date("l, F j, Y, g:i a"); 

$to = "vlevsha@gmail.com";
$subject = "New data submitted!";
$body = "Here is the information submitted to 
www.polycysticliverdisease.com/html/pld_form.php 
from $ip on $date.\n\n
--------------------------------\n\n
name: $name \n\n
email address: $email \n\n
subject: $form_subject \n\n
comment: $message";
//mail($to, $subject, $body);

// Obtain file upload vars    
$fileatt      = $_FILES['uploadedfile']['tmp_name'];    
$fileatt_type = $_FILES['uploadedfile']['type'];    
$fileatt_name = $_FILES['uploadedfile']['name'];

if (is_uploaded_file($fileatt)) {    
 // Read the file to be attached ('rb' = read binary)    
 $file = fopen($fileatt,'rb');    
 $data = fread($file,filesize($fileatt));    
 fclose($file);

 // Generate a boundary string    
 $semi_rand = md5(time());    
 $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";    

 // Add the headers for a file attachment    
 $headers .= "\nMIME-Version: 1.0\n" .    
             "Content-Type: multipart/mixed;\n" .    
             " boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message    
 $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";

// Base64 encode the file data    
 $data = chunk_split(base64_encode($data));

 // Add file attachment to the message    
 $message .= "--{$mime_boundary}\n" .    
             "Content-Type: {$fileatt_type};\n" .    
             " name=\"{$fileatt_name}\"\n" .    
             "Content-Disposition: attachment;\n" .    
             " filename=\"{$fileatt_name}\"\n" .    
             "Content-Transfer-Encoding: base64\n\n" .    
             $data . "\n\n" .    
             "--{$mime_boundary}--\n";    
}

// Send the message    
$ok = @mail($to, $subject, $body, $headers);    
if ($ok) {    
 echo "<p>Mail sent! Yay PHP!</p>";    
} else {    
 echo "<p>Mail could not be sent. Sorry!</p>";    
}

?>

Here is my HTML file upload control:

<input type="submit" name="submit" class="submit" />
<input type="file" name="uploadedfile" class="upload" />

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:42:40+00:00Added an answer on May 15, 2026 at 5:42 pm

    I’d use some mailing library – maybe Swiftmailer. Programming it yourself isn’t worth it (if you’re not doing it for studying purposes of course).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Idea is this: User uploads a file(s) in some temp folder that exist only
I have created a script that will upload files to a general uploads folder,
I created a form in CodeIgniter framework that successfully uploads an image using the
I created a controller which handles file posts, moves uploaded files to a folder
Sample: I've created a minimal set of files that highlight the issue here: http://uploads.omega.org.uk/Foo3.zip
i've created a video upload form and it seems that i get a limit
I'm trying to write to an XML file in the uploads folder in my
I have a php file that uploads images like jpegs and png onto a
I am trying to upload various images into a dynamically created folder on my
Hi: In my application,I have a specified folder in the server side,the client user(authencitationed)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.