php error fopen():

时间:2015-06-29 11:50:11

标签: php

发送带附件代码的电子邮件最近工作正常我们将文件转移到另一个托管服务器idk发生了什么,它显示以下错误,

  

警告:fopen():第106行/home/hugerecruitmetnt/public_html/validatecva.php中的文件名不能为空

     

警告:fread()要求参数1为资源,在第107行的/home/hugerecruitmetnt/public_html/validatecva.php中给出布尔值

     

警告:fclose()要求参数1为资源,第148行/home/hugerecruitmetnt/public_html/validatecva.php中给出布尔值

     

警告:无法修改标题信息 - 已在第150行的/home/hugerecruitmetp/public_html/validatecva.php中通过(输出/home/hugerecruitmetnt/public_html/validatecva.php:106)发送的标题

   <?php 
$name = $_POST['fname']; 
$initial = $_POST['mname']; 
$surname = $_POST['lname']; 
$gender = $_POST['gender']; 
$dob = $_POST['dob'];
$nationality = $_POST['nationality'];
$address = $_POST['fulladdress'];
$passport = $_POST['passportno'];
$passexpiry = $_POST['passexpiry'];
$mobile = $_POST['mobile'];
$email_address = $_POST['email'];
$filename=$_FILES["newfile"]["name"]; 
$filetype=$_FILES["newfile"]["type"]; 
$filesize=$_FILES["newfile"]["size"]; 
$filetemp=$_FILES["newfile"]["tmp_name"]; 

if($filetype=="application/octet-stream" or $filetype=="text/plain" or $filetype=="application/msword" or $filetype=="application/zip" or $filetype=="application/pdf" or $filetype=="application/vnd.openxmlformats-officedocument.wordprocessingml.document") 
{ 

$message= '<table cellspacing="0" cellpadding="8" border="0" width="400"> 
<tr> 
<td colspan="2"></td> 
</tr> 
<tr bgcolor="#eeeeee"> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fname.'  '.$initial.'  '.$surname.'</td> 
</tr> 
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> 
<tr bgcolor="#eeeeee"> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Gender</strong></td> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$gender.'</td> 
</tr> 
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> 
<tr bgcolor="#eeeeee"> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Date Of Birth</strong></td> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$dob.'</td> 
</tr> 
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> 
<tr bgcolor="#eeeeee"> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>nationality</strong></td> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$nationality.'</td> 
</tr> 
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> 
<tr bgcolor="#eeeeee"> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address</strong></td> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fulladdress.'</td> 
</tr> 
<tr bgcolor="#eeeeee"> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Passport No</strong></td> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$passportno.'</td> 
</tr> 
<tr bgcolor="#eeeeee"> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Passport Expiry</strong></td> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$passexpiry.'</td> 
</tr> 
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> 
<tr bgcolor="#eeeeee"> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Email</strong></td> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$email.'</td> 
</tr> 
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> 

<tr bgcolor="#eeeeee"> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Mobile</strong></td> 
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$mobile.'</td> 
</tr>               

<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> 
</table> 
'; 

// MAIL SUBJECT 
$subject = "Posted CV From "; 

// TO MAIL ADDRESS 
$to = 'email@email.com';



/* 
// MAIL HEADERS 

$headers  = "MIME-Version: 1.0\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\n"; 
$headers .= "From: Name <name@name.com>\n"; 

*/ 
// MAIL HEADERS with attachment 
$fp = fopen( $newfile, "rb"); 
$file = fread($fp, $newfile_size); 
$file = chunk_split(base64_encode($file)); 
$num = md5(time()); 

//Normal headers 

$headers  = "From: $name<$email>\r\n"; 
$headers  .= "MIME-Version: 1.0\r\n"; 
$headers  .= "Content-Type: multipart/mixed; "; 
$headers  .= "boundary=".$num."\r\n"; 
$headers  .= "--$num\r\n"; 

// This two steps to help avoid spam    

$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n"; 
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";          

// With message 

$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n"; 
$headers .= "Content-Transfer-Encoding: 8bit\r\n"; 
$headers .= "".$message."\n"; 
$headers .= "--".$num."\n";  

// Attachment headers 

$headers  .= "Content-Type:".$newfile_type." "; 
$headers  .= "name=\"".$newfile_name."\"r\n"; 
$headers  .= "Content-Transfer-Encoding: base64\r\n"; 
$headers  .= "Content-Disposition: attachment; "; 
$headers  .= "filename=\"".$newfile_name."\"\r\n\n"; 
$headers  .= "".$file."\r\n"; 
$headers  .= "--".$num."--"; 



// SEND MAIL 

@mail($to, $subject, $message, $headers); 


fclose($fp); 

header('Location: thankscv.php');
} 
else 
{ 
echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Wrong file format. Mail was not sent.</font>'; 
//echo "<script>window.location.href='careers.html';</script>"; 
} 

2 个答案:

答案 0 :(得分:1)

解决问题

隐藏警告只需使用“@” 例如:@fopen,@ frread,@ fclose

Phew 3hrs浪费了解决这个警告

答案 1 :(得分:0)

上传临时文件的默认大小为2mb 增加尺寸

build/release/obj/extproc/http_job.o

upload_max_filesize=2M

在php.ini xampp中,然后重新启动xampp。我希望你不会得到任何错误,并且文件也会被阅读。

php.ini xampp see figure