コード例 #1
0
ファイル: add.php プロジェクト: WanSpi/wcms
 public function init()
 {
     $this->view = false;
     $res = array();
     foreach ($_FILES as $file) {
         preg_match("/\\/(.+)/", $file["type"], $type);
         $url = $this->createPath() . "." . $type[1];
         move_uploaded_file($file["tmp_name"], $url);
         $image = new images();
         $image->url = $url;
         $image->name = $file["name"];
         $image->size = $file["size"];
         $image->save();
         $img = images::findFirst(array("where" => "url = '{$url}'"));
     }
     echo json_encode(array("id" => $img->id, "url" => $image->url), JSON_FORCE_OBJECT);
 }
コード例 #2
0
ファイル: get.php プロジェクト: WanSpi/wcms
 public function init()
 {
     $this->view = false;
     $url = $this->getUrl();
     $id = $url[count($url) - 1];
     $image = images::findFirst(array("where" => "id = {$id}"));
     $file_extension = strtolower(substr(strrchr($image->url, "."), 1));
     switch ($file_extension) {
         case "gif":
             $ctype = "image/gif";
             break;
         case "png":
             $ctype = "image/png";
             break;
         case "jpeg":
         case "jpg":
             $ctype = "image/jpeg";
             break;
         default:
     }
     header('Content-type: ' . $ctype);
     echo file_get_contents($image->url);
     return false;
 }