How to read and send resource?
<p>I need to generate and send log data to the mail in <code>csv</code> format. Here is my code:</p>

<pre><code>public function sendMail(){
    $csv = $this-&gt;createCSV();
    $subject = $this-&gt;getMessage('subject');
    $message = $this-&gt;getMessage('message');
    $headers = $this-&gt;generateHeaders($csv, $message);

    mail('my_mail@gmail.com', $subject, $message, $headers);
}

private function createCSV(){
    $data = $this-&gt;getAVG();

    $csv = fopen('php://temp', 'w+');

    // long statistics generation

    fclose($csv);

    return $csv;
}

private function generateHeaders($file, $message){
    $boundary = md5(uniqid(time()));

    $headers = 'MIME-Version: 1.0'."\r\n";
    $headers .= 'Content-Type: multipart/mixed; boundary="'.$boundary."\"\r\n";  
    $headers .= 'From: noreplay@'.$_SERVER['SERVER_NAME']."\r\n";

    $headers .= '--'.$boundary."\r\n";

    $headers .= "Content-Type: text/html; charset=utf-8\r\n";
    $headers .= "Content-Transfer-Encoding: base64\r\n";
    $headers .= "\r\n";
    $headers .= chunk_split(base64_encode($message));

    $headers .= '--'.$boundary."\r\n";

    $headers .= "Content-Type: text/csv; name=\"ServersLogs.csv\"\r\n";
    $headers .= "Content-Transfer-Encoding: base64\r\n";
    $headers .= "Content-Disposition: attachment; filename=\"ServersLogs.csv\"\r\n";
    $headers .= "\r\n";
    $headers .= chunk_split(base64_encode(readfile($file)));

    $headers .= "\r\n--".$boundary."--\r\n"; 

    return $headers;
}
</code></pre>

<p>The problem is that i cant save file on the server, so i use <a href="http://www.php.net/manual/en/wrappers.php.php" rel="nofollow">php://</a>, but after it can't read a file...</p>
