\n"; if (!file_exists($file)) { echo "Error: File does not exist."; exit(); } $allowedExtensions = array("png", "jpg", "jpeg", "gif", "tif", "tiff", "bmp"); if (!in_array($extension, $allowedExtensions)) { echo "Error: Extension is not allowed."; unlink($file); exit(); } $fileSize = filesize($file); echo "Size: ".$fileSize."
\n"; list($width, $height, $type, $attr) = getimagesize($file); if (!isset($width) || !isset($height)) { echo "Error: Cannot read image."; unlink($file); exit(); } echo "Width: ".$width." Height: ".$height."
\n"; $hash = md5_file($file); if ($hash==NULL) { echo "Error: Unable to hash image."; unlink($file); exit(); } echo "Hash: ".$hash."
\n"; $newFile = "./data/".$hash.".".$extension; if (file_exists($newFile)) { echo "Error: File already uploaded."; unlink($file); exit(); } $ocr = ""; if (file_exists("./ocr")) { $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w") ); $process = proc_open("./ocr \"".$file."\"", $descriptorspec, $pipes, getcwd()); fclose($pipes[0]); while (is_resource($process)) { $read = $pipes; $write = null; $except = null; $result = stream_select($read, $write, $except, 30); if ($result==0) { fclose($pipes[1]); fclose($pipes[2]); proc_terminate($process,9); break; } else if ($result>0) { $line = fread($pipes[1], 8192); if (strlen($line)==0) { fclose($pipes[1]); fclose($pipes[2]); proc_close($process); break; } $ocr .= $line; } } echo "OCR: ".htmlspecialchars($ocr, ENT_COMPAT | ENT_HTML401, 'UTF-8', true)."
\n"; } $tags = array(); $external_data = ""; $plugins = glob("./external_data_plugins/*.php"); for ($pluginIndex=0; $pluginIndex\n"; $thumbFile = "./thumbs/".$hash.".".$extension; $target = 150; $newWidth = $width; $newHeight = $height; if ($width>$target || $height>$target) { $widthFactor = $target/$width; $heightFactor = $target/$height; $scaleFactor = 1; if ($widthFactor<$heightFactor) $scaleFactor = $widthFactor; else $scaleFactor = $heightFactor; $newWidth = round($width*$scaleFactor); $newHeight = round($height*$scaleFactor); } if ($type==IMAGETYPE_GIF) { $tmp = "./thumbs/coalesce".rand().".gif"; system($_MGM['imagemagick']."convert \"".$file."\" -coalesce \"".$tmp."\""); system($_MGM['imagemagick']."convert -size ".$width."x".$height." \"".$tmp."\" -resize ".$newWidth."x".$newHeight." \"".$thumbFile."\""); unlink($tmp); } else { system($_MGM['imagemagick']."convert -size ".$width."x".$height." \"".$file."\" -resize ".$newWidth."x".$newHeight." \"".$thumbFile."\""); } chmod($thumbFile, 0666); echo "Saved thumbnail.
\n"; rename($file, $newFile); echo "Moved Original.
\n"; databaseQuery("INSERT INTO images (user_id,hash,extension,name,file_size,width,height,thumb_file_size,thumb_width,thumb_height,tags,external_data,ocr,time) VALUES (%s,%s,%s,%s,%d,%d,%d,%d,%d,%d,%s,%s,%s,%d)", $_MGM['user']['docid'], $hash, $extension, $filename, $fileSize, $width, $height, filesize($thumbFile), $newWidth, $newHeight, implode(" ", $tags), $external_data, $ocr, filemtime($newFile)); echo "Complete.
\n"; exit(); } $files = glob("./load/*"); require_once("header.php"); ?> Processing...