Jump to content

[SOLVED] Need help getting rid of errors


hacksurfin79

Recommended Posts

I recently switched hosting companies and now I have problems with a form that work  perfect before.  I am sure it is an easy fix but cannot figure it out.  If filling out the form I don't attach anything I get this message. But if I attach a file it works fine.

 

Warning: file() [function.file]: Filename cannot be empty in /home/patchss/public_html/free_quote.php on line 26

 

Warning: file() [function.file]: Filename cannot be empty in /home/patchss/public_html/free_quote.php on line 106

 

Warning: Cannot modify header information - headers already sent by (output started at /home/patchss/public_html/free_quote.php:26) in /home/patchss/public_html/free_quote.php on line 165

 

I spoke to my host and we turned off the error messages in the ini file.  But they told me that I need to enable output buffering on the page.  I have no idea what the OB is so can someone tell me if it is right?  and What should the code be and where?

 

Link to comment
https://forums.phpfreaks.com/topic/163417-solved-need-help-getting-rid-of-errors/
Share on other sites

Cannot modify header information

 

99% of the time that error occurs if you send a header before and another header right away in your php script.. and they both collide in a single request.

If that wasn't a problem with old host.. that means new host has some kinda hijack code maybe a hidden ad iframe or something running on your scripts that does some requests before you process your script.

 

Either way u can either make a queue to output each script each at a time not all at once. (thats how I fix modify header errors)..

Then the quick fix would be using ob_start();

 

like I found this on google

 

Anyone who uses ob_start() is just IMO a lazy programmer and always takes the quick route due to improper header handling. If cookie/session/other header calls are creating header errors, you simply rearrange your script to accommodate the correct logic - send your headers than your output. Simple as that.

<?php

 

set_time_limit(0);

 

if(trim($_POST["Submit"])=="Submit")

{

$Name=trim($_POST["Name"]);

$email=trim($_POST["email"]);

$phone1=trim($_POST["phone1"]);

$phone2=trim($_POST["phone2"]);

$phone3=trim($_POST["phone3"]);

$cell1=trim($_POST["cell1"]);

$cell2=trim($_POST["cell2"]);

$cell3=trim($_POST["cell3"]);

$quantity=trim($_POST["quantity"]);

$size=trim($_POST["size"]);

$embroidery=trim($_POST["embroidery"]);

$artwork_method=trim($_POST["artwork_method"]);

$comments=trim($_POST["comments"]);

 

$attach = $_FILES['attach']['tmp_name'];

$attach_size = $_FILES['attach']['size'];

$attach_type = $_FILES['attach']['type'];

$attach_name = $_FILES['attach']['name'];

 

if (file($attach) && $attach_size>10000000) $msg="File size should not be more than 10 MB.";

else

{

/*if(!($attach_type=="application/msword" || $attach_type=="application/doc" || $attach_type=="appl/text" || $attach_type=="application/vnd.msword" || $attach_type=="application/vnd.ms-word" || $attach_type=="application/winword" || $attach_type=="application/word" || $attach_type=="application/x-msw6" || $attach_type=="application/x-msword" || $attach_type=="zz-application/zz-winassoc-doc" ||

$attach_type=="application/pdf" || $attach_type=="application/x-pdf" || $attach_type=="application/acrobat" || $attach_type=="applications/vnd.pdf" || $attach_type=="text/pdf" || $attach_type=="text/x-pdf" ||

$attach_type=="application/rtf" || $attach_type=="application/x-rtf" || $attach_type=="text/rtf" || $attach_type=="text/richtext" || $attach_type=="application/x-soffice" ||

$attach_type=="application/msexcel" || $attach_type=="application/x-msexcel" || $attach_type=="application/x-ms-excel" || $attach_type=="application/vnd.ms-excel" || $attach_type=="application/x-excel" || $attach_type=="application/x-dos_ms_excel" || $attach_type=="application/xls" || $attach_type=="application/x-xls" || $attach_type=="zz-application/zz-winassoc-xls"))*/

 

if(preg_match('/\\.(exe|com|bat|api|bpl|dll|chm|drv|ocx|pif|scr|sys|wsh|vb)$/i', $attach_name))

{

$msg= "This file is not allowed";

}

else

{

$HtmlMessage=" <html>

<body>

<table width='100%' cellpadding='2' cellspacing='1' border='0'>

<tr valign='top'>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'> </td>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>IP Address</td>

<td align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>:</td>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;'>".$_SERVER['REMOTE_ADDR']."</td>

</tr>

<tr valign='top'>

<td width='3%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'> </td>

<td width='20%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>Name </td>

<td width='3%' align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>:</td>

<td width='74%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;'>".$Name."</td>

</tr>

<tr valign='top'>

<td width='3%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'> </td>

<td width='20%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>Daytime phone number</td>

<td width='3%' align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>:</td>

<td width='74%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;'>".$phone1."-".$phone2."-".$phone3."</td>

</tr>

<tr valign='top'>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'> </td>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>Email </td>

<td align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>:</td>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;'>".$email."</td>

</tr>

<tr valign='top'>

<td width='3%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'> </td>

<td width='20%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>Quantity</td>

<td width='3%' align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>:</td>

<td width='74%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;'>".$quantity."</td>

</tr>

<tr valign='top'>

 

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'> </td>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>Size </td>

<td align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>:</td>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;'>".$size.""</td>

</tr>

<tr valign='top'>

<td width='3%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'> </td>

<td width='20%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>Embroidery </td>

<td width='3%' align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>:</td>

<td width='74%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;'>".$embroidery."</td>

</tr>";

 

if($artwork_method=="notavailable")

{

$HtmlMessage.= "<tr valign='top'>

<td width='3%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'> </td>

<td width='20%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>Method of Artwork Submission</td>

<td width='3%' align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>:</td>

<td width='74%' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;'>No artwork is available, please contact me.</td>

</tr>";

}

$HtmlMessage.="<tr valign='top'>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'> </td>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>Comments</td>

<td align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold'>:</td>

<td style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;'>".nl2br($comments)."</td>

</tr>

</table>

</body>

</html>";

 

if (file($attach))

{

$headers = "From: ".$email;

 

// Read the file to be attached ('rb' = read binary)

$file = fopen($attach,'rb');

$data = fread($file,filesize($attach));

fclose($file);

 

// Generate a boundary string

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

 

// Add the headers for a file attachment

$headers .= "\nMIME-Version: 1.0\n" .

"Content-Type: multipart/mixed;\n" .

" boundary=\"{$mime_boundary}\"";

 

// Add a multipart boundary above the plain message

$message = "This is a plain message\n\n" .

"--{$mime_boundary}\n" .

"Content-Type: text/html; charset=\"iso-8859-1\"\n" .

"Content-Transfer-Encoding: 7bit\n\n" .

$HtmlMessage. "\n\n";

 

// Base64 encode the file data

$data = chunk_split(base64_encode($data));

 

// Add file attachment to the message

$message .= "--{$mime_boundary}\n" .

"Content-Type: {$attach_type};\n" .

" name=\"{$attach_name}\"\n" .

//"Content-Disposition: attachment;\n" .

//" filename=\"{$fileatt_name}\"\n" .

"Content-Transfer-Encoding: base64\n\n" .

$data . "\n\n" .

"--{$mime_boundary}--\n";

 

$to="[email protected]";

 

$Subject="PatchSuperstore Quantity $quantity";

@mail ($to, "$Subject", $message, $headers);

}

else

{

$to="[email protected]";

 

$headers .= 'From: ' . $email . "\n";

$headers .= 'To: ' . $to . "\n";

$headers .= 'Return-Path: ' . $email . "\n";

$headers .= 'MIME-Version: 1.0' ."\n";

$headers .= 'Content-Type: text/HTML; charset=ISO-8859-1' ."\n";

$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\n";

$headers .= $HtmlMessage . "\n";

 

$Subject="PatchSuperstore Quantity $quantity";

@mail ('', "$Subject", '', $headers);

}

 

header("location:thankyou.htm");

}

}

}?>

well it's obvious you haven't made that script yourself.. I found a similar one here

 

http://www.angelfire.com/members/tradingpins4less/freequote.php

 

 

which umm could possibly help you solve it faster.. if you don't care just add ob_start(); at 2nd line.

1. the Error is telling you the problem!

2. use CODE tags

3. don't bump without giving more information

4. you could just omit the error ie

if (@file($attach) && $attach_size>10000000)      $msg="File size should not be more than 10 MB.";

or

if (!empty($attach) && file($attach) && $attach_size>10000000)      $msg="File size should not be more than 10 MB.";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.