Home  >  Article  >  Backend Development  >  sae image generation

sae image generation

WBOY
WBOYOriginal
2016-07-25 08:51:041397browse
Put it on sae and generate the image online.
http://tuzhong.sinaapp.com
  1. require('db.php');
  2. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  3. $stor = new SaeStorage();
  4. / /Make sure there is enough space
  5. $stor_size=$stor->getDomainCapacity($domain);//Get the used size
  6. if($stor_size>=2*1000*1024*1024)
  7. {
  8. //Delete 2 File
  9. }
  10. $bitfile = $_FILES[upfile];
  11. $picfile = $_FILES[uppic] ;
  12. if($bitfile['size'] >=1024 * 1024 * 10){
  13. echo '< ;script>alert("Please upload a seed file smaller than 10m!")';
  14. return ;
  15. }
  16. if(empty($picfile)){//If you uploaded a picture
  17. //File type is a picture, pjpeg is the jpg type in ie, and the file size must not be larger than 10m
  18. if (in_array($picfile['type'], array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png'))
  19. && $picfile['size'] <=1024 * 1024 * 10) {
  20. $fp = fopen($picfile['tmp_name'], "rb");
  21. $picdata = fread ($fp, filesize($picfile['tmp_name']));
  22. }else{
  23. echo '<script>alert("Please upload pictures smaller than 10m!")</script>';
  24. return ;
  25. }
  26. }else{
  27. //If no file is uploaded, use this picture
  28. $picdata = $stor->read($domain,$BasePicture);
  29. }
  30. $fp = fopen($bitfile['tmp_name' ],'rb');
  31. $bitdata = fread($fp,filesize($bitfile['tmp_name']));
  32. //Merge temporary files
  33. $fileName = md5(time()).". png";
  34. $filePath = SAE_TMP_PATH.$fileName;
  35. $fp = fopen($filePath,'w');
  36. fwrite($fp,$picdata);
  37. fwrite($fp,$bitdata);
  38. fclose( $fp);
  39. //Upload files
  40. $url = $stor->upload($domain,$fileName,$filePath);
  41. echo "<script>window.location.href="down.php? url=$url"</script>";
  42. }
  43. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn