1. Save remote image to storage
Where public is the container name in storage, "Directory 1/Directory 2/" is the path under the container $file _content is the resulting file data
1 $s New saestorage (); 2 $file _content file_get_contents (' HTTP://ABC.PMG '); // The remote picture address in parentheses 3 $s->write (' Public ', $file _content
Upload image on 2.sae
With the thinkphp framework built-in upload class can be perfectly compatible with the SAE environment, but after the successful upload on the SAE path is the file name, you need to manually add the upload container path, that is, in the project need to replace the path of __ing__ or __public__, the way to get the path is as follows:
1 $storage new \saestorage (); // instantiate the Saestorage class 2 $uploadsae $storage->geturl (' Public ', ' Upload '); //
where public is the container name in storage, "Upload" is the path under the container; The replacement method can use the template substitution method of TP:
1 ' tmpl_parse_string ' = = array(2 ' __ing__ ' $st- >geturl (' Public ', ' upload '),3 $st->geturl (' Application ', ' user ')4 5 )
3: Generate thumbnails and save them in the appropriate container If the Generate thumbnail method with TP can also be successfully run on the SAE, the following uses the method provided by SAE to generate thumbnails
1 $f=New\saefetchurl ();2 $img _data=$f->fetch ("Picture url");//read file with filename3 $img=New\saeimage ();4 $img->setdata ($img _data);5 $img->resize ($width,$height);//Specifies the width and height of the thumbnail image6 $new _data=$img-exec();//performs processing and returns the processed binary data7 if($new _data===false){//output error when picture processing fails8 return false;9 }Ten $s->write (' Public ', ' Directory 1/directory 2/abc.png ',$file _content); One $img-exec(' jpg ',true);//If you do not want to save, but want to output the use:
4: Messages without HTML (HTML not supported)
1 $mail=New\saemail ();2 $body= "Dear User: Thank you for registering a new account with this website. Please click on the link to activate your account ";3 $mail->setattach (Array("My_photo" and "Photo binary data"));//If you send a picture4 $ret=$mail->quicksend ("Recipient's mailbox", ' message header ',$body, ' sender's mailbox ', ' sender's email password ', ' smtp.139.com ', 25;//smtp.139.com is the host number, 25 is the SMTP server port5 $mail->clean ();//clear the previous object for loop forwarding
5: Mail with HTML (HTML supported)
where setopt () functions only in Send () sending commands and does not work in fast send quicksend ();
1 $mail=New\saemail ();2 $mail->setopt (Array(3' From ' = ' [email protected] ',//e-Mail for example [email protected]4' to ' + =$data[' Email '],//Receive Mailbox5' Smtp_host ' = ' smtp.139.com ',//SMTP Server6' Smtp_port ' = 25,//Port7' Smtp_username ' = ' [email protected] ',//full name of the account, [email protected], as above8' Smtp_password ' = ' Send email password ',9' Subject ' = ' title ',Ten' Content ' =$body,//Send content One' Content_Type ' = ' html '//send format, default is Text A ) - ); - $ret=$mail-send (); the $mail-Clean (); - if($ret==false){ - Var_dump($mail->errno (),$mail->errmsg ());//Print error message - return false; +}Else{ - return true; +}
Want to know more about parameters: http://apidoc.sinaapp.com/class-SaeMail.html
SAE Cloud platform upload images and send mail