コード例 #1
0
ファイル: class_image.php プロジェクト: morilo/ptpimg
 function populate()
 {
     global $DB, $Cache;
     if (!empty($this->Contents) || !$this->Auth || $this->Type < 0) {
         return false;
     }
     $this->Verified = false;
     $Results = array();
     switch ($this->Type) {
         case -1:
         case 0:
             return false;
             break;
             // ajax upload
         // ajax upload
         case 1:
             // Load the image into RAM
             $this->Contents = file_get_contents("php://input");
             if (empty($this->Contents)) {
                 return false;
             }
             // Generate a unique ID and move it to the ramdisk
             $Unique = uniqid();
             $TmpFile = fopen(TMP_PREFIX . $Unique, 'w+');
             fwrite($TmpFile, $this->Contents);
             $this->Contents = '';
             // Free some memory
             // Fetch the properties of the image
             $Verify = new ImageVerification(TMP_PREFIX . $Unique);
             if (!$Verify->verify()) {
                 continue;
             }
             $Data = $Verify->EphemeralData;
             $DB->query("SELECT Code, Extension FROM uploads WHERE NewHash='" . db_string($Data['md5']) . "'");
             if ($DB->record_count() > 0) {
                 unlink(TMP_PREFIX . $Unique);
                 list($Code, $Extension) = $DB->next_record();
                 $Results[] = array("status" => 13, "code" => $Code, "ext" => $Extension);
                 continue;
             }
             $Code = '';
             while ($Code = randFN()) {
                 if (!file_exists(IMG_DIR . '/' . $Code)) {
                     break;
                 }
             }
             rename(TMP_PREFIX . $Unique, IMG_DIR . '/' . $Code);
             switch ($Data['type']) {
                 case 1:
                 case 2:
                 case 3:
                     $DB->query("INSERT INTO uploads\n\t\t\t\t\t\t\t\t\t(NewHash, Extension, Code, Resolution, Size, Type)\n\t\t\t\t\t\t\t\t\tVALUES(\n\t\t\t\t\t\t\t\t\t'" . db_string($Data['md5']) . "',\n\t\t\t\t\t\t\t\t\t'" . db_string($Data['ext']) . "',\n\t\t\t\t\t\t\t\t\t'" . db_string($Code) . "',\n\t\t\t\t\t\t\t\t\t'" . db_string($Data['res']) . "',\n\t\t\t\t\t\t\t\t\t'" . db_string($Data['size']) . "',\n\t\t\t\t\t\t\t\t\t'" . db_string($Data['type']) . "')");
                     if ($DB->affected_rows() > 0) {
                         $Results[] = array("status" => 1, "code" => $Code, "ext" => $Data['ext']);
                     }
                     break;
             }
             break;
             // file
         // file
         case 2:
             for ($i = 0; $i < count($this->Special['name']); $i++) {
                 if (!is_uploaded_file($this->Special['tmp_name'][$i])) {
                     return false;
                 }
                 // Load the image into RAM
                 $this->Contents[$i] = file_get_contents($this->Special['tmp_name'][$i]);
                 if (empty($this->Contents[$i])) {
                     return false;
                 }
                 // Generate a unique ID and move it to the ramdisk
                 $Unique = uniqid();
                 $TmpFile = fopen(TMP_PREFIX . $Unique, 'w+');
                 fwrite($TmpFile, $this->Contents[$i]);
                 $this->Contents = '';
                 // Free some memory
                 // Fetch the properties of the image
                 $Verify = new ImageVerification(TMP_PREFIX . $Unique);
                 if (!$Verify->verify()) {
                     continue;
                 }
                 $Data = $Verify->EphemeralData;
                 $DB->query("SELECT Code, Extension FROM uploads WHERE NewHash='" . db_string($Data['md5']) . "'");
                 if ($DB->record_count() > 0) {
                     unlink(TMP_PREFIX . $Unique);
                     list($Code, $Extension) = $DB->next_record();
                     $Results[] = array("status" => 13, "code" => $Code, "ext" => $Extension);
                     continue;
                 }
                 $Code = '';
                 while ($Code = randFN()) {
                     if (!file_exists(IMG_DIR . '/' . $Code)) {
                         break;
                     }
                 }
                 rename(TMP_PREFIX . $Unique, IMG_DIR . '/' . $Code);
                 switch ($Data['type']) {
                     case 1:
                     case 2:
                     case 3:
                         $DB->query("INSERT INTO uploads\n\t\t\t\t\t\t\t\t\t\t(NewHash, Extension, Code, Resolution, Size, Type)\n\t\t\t\t\t\t\t\t\t\tVALUES(\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['md5']) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['ext']) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Code) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['res']) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['size']) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['type']) . "')");
                         if ($DB->affected_rows() > 0) {
                             $Results[] = array("status" => 1, "code" => $Code, "ext" => $Data['ext']);
                         }
                         break;
                 }
             }
             break;
         case 3:
             if (empty($this->Special)) {
                 return false;
             }
             if (!is_array($this->Special)) {
                 // Convert to an array
                 $Urls = array();
                 if (strpos($this->Special, "\n")) {
                     $Urls = explode("\n", $this->Special);
                 } else {
                     $Urls[] = $this->Special;
                 }
                 $this->Special =& $Urls;
             }
             foreach ($this->Special as $URL) {
                 // Load the image into RAM
                 $Image = file_get_contents($URL);
                 // Generate a unique ID and move it to the ramdisk
                 $Unique = uniqid();
                 $TmpFile = fopen(TMP_PREFIX . $Unique, 'w+');
                 fwrite($TmpFile, $Image);
                 $Image = '';
                 // Free some memory
                 // Fetch the properties of the image
                 $Verify = new ImageVerification(TMP_PREFIX . $Unique);
                 if (!$Verify->verify()) {
                     continue;
                 }
                 $Data = $Verify->EphemeralData;
                 $DB->query("SELECT Code, Extension FROM uploads WHERE NewHash='" . db_string($Data['md5']) . "'");
                 if ($DB->record_count() > 0) {
                     unlink(TMP_PREFIX . $Unique);
                     list($Code, $Extension) = $DB->next_record();
                     $Results[] = array("status" => 13, "code" => $Code, "ext" => $Extension);
                     continue;
                 }
                 $Code = '';
                 while ($Code = randFN()) {
                     if (!file_exists(IMG_DIR . '/' . $Code)) {
                         break;
                     }
                 }
                 rename(TMP_PREFIX . $Unique, IMG_DIR . '/' . $Code);
                 switch ($Data['type']) {
                     case 1:
                     case 2:
                     case 3:
                         $DB->query("INSERT INTO uploads\n\t\t\t\t\t\t\t\t\t\t(NewHash, Extension, Code, Resolution, Size, Type)\n\t\t\t\t\t\t\t\t\t\tVALUES(\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['md5']) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['ext']) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Code) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['res']) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['size']) . "',\n\t\t\t\t\t\t\t\t\t\t'" . db_string($Data['type']) . "')");
                         if ($DB->affected_rows() > 0) {
                             $Results[] = array("status" => 1, "code" => $Code, "ext" => $Data['ext']);
                         }
                         break;
                 }
             }
             break;
     }
     $this->Results =& $Results;
     if (count($this->Results) > 0) {
         return true;
     } else {
         return false;
     }
 }
コード例 #2
0
ファイル: index_v2.php プロジェクト: morilo/ptpimg
 fwrite($tmpFile, $Image);
 $Data = getdata("/tmpfs/ptpimg_" . $Unique);
 $ext = $Data['ext'];
 $res = $Data['res'];
 $ImageType = $Data['type'];
 $size = $Data['size'];
 $hash = $Data['md5'];
 $DB->query("SELECT Code, Extension FROM uploads WHERE NewHash='" . db_string($hash) . "'");
 if ($DB->record_count() > 0) {
     unlink("/tmpfs/ptpimg_" . $Unique);
     list($Code, $Extension) = $DB->next_record();
     $results[] = array("status" => 13, "code" => $Code, "ext" => $Extension);
     continue;
 }
 $code = '';
 while ($code = randFN()) {
     if (!file_exists('raw/$code')) {
         break;
     }
 }
 // Flush image contents to a temp file
 //$src=tempnam("/tmp", "ptpimg.");
 $src = "raw/{$code}";
 rename("/tmpfs/ptpimg_" . $Unique, $src);
 // Read image type
 // 1-gif, 2-jpeg, 3-png
 switch ($ImageType) {
     case 1:
     case 2:
     case 3:
         $DB->query("INSERT INTO uploads (NewHash, UserID, Extension, Code, Resolution, Size, Type) VALUES('" . db_string($hash) . "', '" . db_string($_GET['uid']) . "', '" . db_string($ext) . "', '" . db_string($code) . "', '" . db_string($res) . "', '" . db_string($size) . "', '" . db_string($ImageType) . "')");