示例#1
0
文件: index.php 项目: morilo/ptpimg
<?php

// ptpimg v2 (circa dec 2011)
// Avoid error reporting
//error_reporting(0);
require 'script_start.php';
require ASSETS . '/class_image.php';
show_header();
print_r($LoggedUser);
// Test the verification against getData()
$Verify = new ImageVerification('/home/ptpimg/public_html/raw/d6rkrm');
if (!$Verify->verify()) {
    // It's not valid, you say?
    // Delete image?
    // unlink($f);
} else {
    //
    var_dump($Verify->EphemeralData);
}
show_footer();
//$Image = new Image('e8219v');
//$Image = new Image('e8219v');
//$Image->access();
示例#2
0
 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;
     }
 }