php接收表单文件为空,表单提交后php – $_FILES为空

参见英文答案 >

Why would $_FILES be empty when uploading files to PHP?18

我正在使用标准的PHP函数来上传文件以用作PHPMailer的附件.

First Name *

Email Address *

Contact Number *

Message *

Send Us Your CV *

此表单将提交到邮件构建和发送的以下PHP处理程序:

require_once("class.PHPmailer.PHP");

$first_name = $_POST['first_name']; // required

$email_from = $_POST['email']; // required

$telephone = $_POST['telephone']; // required

$comments = $_POST['comments']; // required

echo "just got form values
";

echo $_FILES['upload']['name'].'
';

$email_message = "Form details below.
";

function clean_string($string) {

$bad = array("content-type","bcc:","to:","cc:","href");

return str_replace($bad,"",$string);

}

$email_message .= "Name: ".clean_string($first_name)."\n";

$email_message .= "Email: ".clean_string($email_from)."\n";

$email_message .= "Contact: ".clean_string($telephone)."\n";

$email_message .= "Message:\n".clean_string($comments)."\n";

echo "added text to email
";

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['upload']['name']);

// upload the file

echo "target = ".$target_path."
";

if (isset($_FILES['upload']['size']))

{

if ($_FILES['upload']['size'] > 0)

{

echo 'file size: '.basename($_FILES['upload']['size']).'
';

if (move_uploaded_file($_FILES['upload']['name'],$target_path))

{

echo "The file ". basename( $_FILES['upload']['name'])." has been uploaded
";

// adding an already existing file as an attachment to the email for debugging purposes.

$email->AddAttachment('uploads/CreditReportViewer.pdf');

}

else

{

echo "There was an error uploading the file,please try again!
 ".basename($_FILES['upload']['error']);

}

}

else

{

echo "There was an error uploading the file,please try again!
";

}

}

else

{

echo "No file was found for the upload.
";

}

$email = new PHPMailer();

$email->To = "me@this.com";

$email->From = $email_from;

$email->FromName = $first_name;

$email->Subject = "New Message from Website";

$email->Body = $email_message;

echo "\n mail built...
";

$email->Send();

echo "mail sent!";

?>

问题是$_FILES [‘upload’] [‘name’]未设置.以下是正在写入浏览器的回音:

just got form values

added text to email

target = uploads/

No file was found for the upload.

mail built…

mail sent!

这使我认为我引用了文件上传字段或上传本身不正确.

任何人都可以看到任何问题,或提供一些指导,如果这不是最好的方法呢?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值