Attach image to email without saving to disk

Discussion in 'PHP' started by heals1ic, May 15, 2007.

  1. #1
    Does anyone know of a way to attach jpg image created in php without having to save the file to the server before attaching it?

    I am using this MIME code to attach the image to an email -
    
    for($i=0;$i<$max;$i++)
                {
                    $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i]));
                    $this->header .= "--".$this->boundary."\n";
                    $this->header .= "Content-Type: application/x-zip-compressed; name=".$this->attachment[$i]."\n";
                    $this->header .= "Content-Transfer-Encoding: base64\n";
                    $this->header .= "Content-Disposition: attachment; filename=".$this->attachment[$i]."\n\n";
                    $this->header .= chunk_split(base64_encode($file))."\n";
                    $file = "";
                }
    
    PHP:
    Can I attach the image stored as a variable for instance?
     
    heals1ic, May 15, 2007 IP
  2. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't think it is possible, although you could save it and as soon as it is sent, delete it
     
    bobby9101, May 15, 2007 IP
  3. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Bobby is correct, you could save it to /tmp and it'll auto delete shortly after (saves you some code, not the best practice though)
     
    CodyRo, May 15, 2007 IP