我希望有一封邮件,该邮件发送1)邮件和2)按下“提交”按钮时还将文件上传到服务器。
我的问题现在在第2点。邮件表格已经可以使用了。我使用ajax和PHP。当我按提交时,邮件正在发送,但是没有任何内容上传到我的目录中。我没有任何错误..有人有想法吗?
SEARCH_STATUS findString_chrchr(const char *src, int commaNumber, char *dst, int desLen) {
/* skip commaNumber fields */
while (commaNumber > 0) {
src = strchr(src, ',');
if (!src)
return STR_KEY_NOT_FOUND;
src++;
commaNumber--;
}
int D = 0;
while (src[D] != '\0' && src[D] != ',')
D++;
if (D >= desLen)
return STR_OVERFLOW;
if (D > 0)
memcpy(dst, src, D);
dst[D] = '\0';
return STR_FOUND;
}
db.collection.aggregate([
{ "$project": {
"totalHoursInThisMonth": {
{ "$let": {
"vars": { "date": {
"$filter": {
"input": "$attendance",
"as": "attend",
"cond": {
"$and": [
{ "$gte": ["$$attend.date", startOfMonth] },
{ "$lte": ["$$attend.date", endOfMonth] }
]
}
}
}},
"in": "$$date.totalHours"
}}
}
}}
])
<?php
/*
* CONFIGURE EVERYTHING HERE
*/
$currentDir = getcwd();
$uploadDirectory = "uploads/";
$errors = []; // Store all foreseen and unforseen errors here
$fileExtensions = ['jpeg', 'jpg', 'png']; // Get all the file extensions
$fileName = $_FILES['uploaded_file']['name'];
$fileSize = $_FILES['uploaded_file']['size'];
$fileTmpName = $_FILES['uploaded_file']['tmp_name'];
$fileType = $_FILES['uploaded_file']['type'];
$fileExtension = strtolower(end(explode('.', $fileName)));
$uploadPath = $currentDir . $uploadDirectory . basename($fileName);
if (isset($_POST['submit'])) {
if (!in_array($fileExtension, $fileExtensions)) {
$errors[] = "This file extension is not allowed. Please upload a JPEG or PNG file";
}
if ($fileSize > 2000000) {
$errors[] = "This file is more than 2MB. Sorry, it has to be less than or equal to 2MB";
}
if (empty($errors)) {
$didUpload = move_uploaded_file($fileTmpName, $uploadPath);
if ($didUpload) {
echo "The file " . basename($fileName) . " has been uploaded";
} else {
echo "An error occurred somewhere. Try again or contact the admin";
}
} else {
foreach ($errors as $error) {
echo $error . "These are the errors" . "\n";
}
}
}
$from = '';
$sendTo = '';
$Bcc = '';
// subject of the email
$subject = 'Neue Nachricht von ';
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('firma' => 'Firma', 'anrede' => 'Anrede', 'vorname' => 'Vorname', 'nachname' => 'Nachname', 'strasse' => 'Strasse', 'hausnummer' => 'Hausnummer', 'plz' => 'Plz',
'ort' => 'Ort', 'liefer_strasse' => 'Lieferadresse Straße', 'liefer_hausnummer' => 'Lieferadresse Hausnummer', 'liefer_plz' => 'Lieferadresse PLZ', 'liefer_ort' => 'Lieferadresse Ort', 'lieferant_name' => 'Lieferant Name', 'lieferant_email' => 'Lieferant E-Mail',
'lieferant_phone' => 'Lieferant Tel', 'lieferant_need' => 'Wie haben Sie von uns erfahren?', 'message' => 'Nachricht');
$okMessage = 'Ihre Anfrage wurde erfolgreich abgeschickt. Vielen Dank, wir werden uns zeitnah bei Ihnen melden.';
$errorMessage = 'Es gab einen Fehler beim abschicken des Formulars. Bitte probieren Sie es später nocheinmal oder Schreiben Sie uns direk';
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try {
if (count($_POST) == 0) throw new \Exception('Kontaktformular ist leer');
$emailText = "Eine neue Nachricht vom Kontaktformular\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
// All the neccessary headers for the email.
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
'Bcc:' . $Bcc
);
// Send email
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
} catch (\Exception $e) {
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
// if requested by AJAX request return JSON response
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
} // else just display the message
else {
echo $responseArray['message'];
}
答案 0 :(得分:0)
检查上载文件夹的权限。您的Web服务器正在运行的用户可能无权将文件写入您的上传目录。使用FTP或SSH,您可以将其更改为0755,这样您就可以将上传的内容写入上传目录。