Jump to content

Php form with attachment


rameses

Recommended Posts

I have the following code that ask users to enter the information with an attachment:

    $fp = fopen($strresume, "rb");

    $file = fread($fp, $strresume_size);

 

    $file = chunk_split(base64_encode($file));

    $num = md5(time());

 

        //Normal headers

 

    $headers  = "From: Name<[email protected]>\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:".$strresume_type." ";

      $headers  .= "name=\"".$strresume_name."\"r\n";

      $headers  .= "Content-Transfer-Encoding: base64\r\n";

      $headers  .= "Content-Disposition: attachment; ";

      $headers  .= "filename=\"".$strresume_name."\"\r\n\n";

      $headers  .= "".$file."\r\n";

      $headers  .= "--".$num."--";

 

 

 

    // SEND MAIL

 

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

 

 

    fclose($fp);

 

When try to send the information, it gives the following error message:

Warning: fread(): supplied argument is not a valid stream resource in /var/www/name/name.php on line 102

 

Warning: fclose(): supplied argument is not a valid stream resource in /var/www/name/name.php on line 144

Link to comment
https://forums.phpfreaks.com/topic/186188-php-form-with-attachment/
Share on other sites

I know what $strresume is meant to contain but what does it actually contain? Is the file path valid? The next thing is are your permissions on the file correct?

 

Place this at the top of your script to see what errors are produced.

 

error_reporting(E_ALL) ; ini_set('display_errors', 1);

That gave the following message:

Notice: Undefined variable: strresume in /var/www/iims/akf.php on line 101

 

Notice: Undefined variable: strresume_size in /var/www/iims/akf.php on line 102

 

Warning: fread(): supplied argument is not a valid stream resource in /var/www/iims/akf.php on line 102

 

Notice: Undefined variable: now in /var/www/iims/akf.php on line 117

 

Notice: Undefined variable: strresume_type in /var/www/iims/akf.php on line 129

 

Notice: Undefined variable: strresume_name in /var/www/iims/akf.php on line 130

 

Notice: Undefined variable: strresume_name in /var/www/iims/akf.php on line 133

 

Warning: fclose(): supplied argument is not a valid stream resource in /var/www/iims/akf.php on line 144

 

I'm attaching both index.txt and name.php files for better understand. Thanks for your help Thorpe.

 

[attachment deleted by admin]

It would appear you HostGator account has register globals enabled. This is a bad idea and has been disabled in php by default since 2002 sometime. I haven't looked at your code but form variables don't magically show up any more. If your using the post method, the data you are seeking will be within the $_POST array (the get method uses $_GET).

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.