Skip to content

Commit

Permalink
Create pload.php
Browse files Browse the repository at this point in the history
  • Loading branch information
itzfew authored Apr 11, 2024
1 parent 4f9b17f commit ebaca05
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
$fileTmpPath = $_FILES['file']['tmp_name'];
$fileName = $_FILES['file']['name'];
$fileType = $_FILES['file']['type'];
$fileSize = $_FILES['file']['size'];
$fileUploadPath = 'uploads/' . $fileName;

// Move uploaded file to destination
if (move_uploaded_file($fileTmpPath, $fileUploadPath)) {
// Send email to admin with file attached
$to = 'admin@example.com';
$subject = 'New file uploaded';
$message = 'A new file has been uploaded by a user.';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

// Attach file
$fileContent = file_get_contents($fileUploadPath);
$attachment = chunk_split(base64_encode($fileContent));
$boundary = md5(date('r', time()));
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message = "--_1_$boundary\r\n" .
"Content-Type: multipart/alternative; boundary=\"_2_$boundary\"\r\n" .
"\r\n" .
"--_2_$boundary\r\n" .
"Content-Type: text/plain; charset=\"UTF-8\"\r\n" .
"Content-Transfer-Encoding: 7bit\r\n" .
"\r\n" .
$message . "\r\n" .
"--_2_$boundary--\r\n" .
"--_1_$boundary\r\n" .
"Content-Type: application/octet-stream; name=\"$fileName\"\r\n" .
"Content-Transfer-Encoding: base64\r\n" .
"Content-Disposition: attachment\r\n" .
"\r\n" .
$attachment . "\r\n" .
"--_1_$boundary--";

// Send email
if (mail($to, $subject, $message, $headers)) {
echo json_encode(['success' => true]);
} else {
echo json_encode(['success' => false]);
}
} else {
echo json_encode(['success' => false]);
}
} else {
echo json_encode(['success' => false]);
}
?>

0 comments on commit ebaca05

Please sign in to comment.