3 回答
TA贡献1859条经验 获得超6个赞
第一个问题是您正在处理带有$_POST. 应该是$_FILES。
第二个问题是你应该tmp_name在你的move_uploaded_file函数中使用索引。
第三个问题是foreach如果您上传多个文件,您的循环不正确。
看起来您正在上传目录外的$path_file文件。所以,试试这个:
if (!empty($_FILES) & isset($_FILES['uploaded_file']['tmp_name'])) {
// Create folder uploads if not exists
$path_upload = 'uploads';
createFolderIfNotExist($path_upload);
// create folder with company name if not exists
$path_file = $path_upload . '/mail_upload';
createFolderIfNotExist($path_file);
// create folder with date + id_user
$path_file .= '/' . date('Ymd') . $user->getId();
createFolderIfNotExist($path_file);
foreach ($_FILES['uploaded_file']['name'] as $key => $attachment2) {
move_uploaded_file($_FILES['uploaded_file']['tmp_name'][$key], $path_file . '/' . $attachment2);
$pj = '/' . $path_file . '/' . $attachment2;
// Attachments
$mail->addAttachment($pj); // Optional name
}
}
TA贡献1851条经验 获得超5个赞
使用此链接后将服务器文件权限更改为 777 希望您的问题得到解决。
if (!empty($_FILES) & isset($_FILES['uploaded_file']['tmp_name'])) {
// Create folder uploads if not exists
$path_upload = 'uploads';
if (!file_exists($path_upload)) {
mkdir($path_upload, 0777, true);
}
// create folder with company name if not exists
$path_file = $path_upload . '/mail_upload';
if (!file_exists($path_file)) {
mkdir($path_file, 0777, true);
}
// create folder with date + id_user
$path_file .= '/' . date('Ymd') . $user->getId();
createFolderIfNotExist($path_file);
if (!file_exists($path_file)) {
mkdir($path_file, 0777, true);
}
foreach ($_FILES['uploaded_file']['name'] as $key => $attachment2) {
move_uploaded_file($_FILES['uploaded_file']['tmp_name'][$key], $path_file . '/' . $attachment2);
$pj = '/' . $path_file . '/' . $attachment2;
// Attachments
$mail->addAttachment($pj); // Optional name
}
}
TA贡献1719条经验 获得超6个赞
if (!empty($_FILES) & isset($_FILES['uploaded_file']['tmp_name'])) {
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], "/documents/new/")) {
print "Uploaded successfully!";
} else {
print "Upload failed!";
}
}
- 3 回答
- 0 关注
- 156 浏览
添加回答
举报