'err','reason'=>'Not a valid image'); } if($hash===false) { $hash = getNewHash($ext,6); } if($newsha1) addSha1($hash,$newsha1); mkdir(ROOT.DS.'data'.DS.$hash); $file = ROOT.DS.'data'.DS.$hash.DS.$hash; move_uploaded_file($tmpfile, $file); if(defined('ALT_FOLDER') && ALT_FOLDER) { $altname=ALT_FOLDER.DS.$hash; if(!file_exists($altname) && is_dir(ALT_FOLDER)) { copy($file,$altname); } } if(defined('LOG_UPLOADER') && LOG_UPLOADER) { $fh = fopen(ROOT.DS.'data'.DS.'uploads.txt', 'a'); fwrite($fh, time().';'.$url.';'.$hash.';'.getUserIP()."\n"); fclose($fh); } return array('status'=>'ok','hash'=>$hash,'url'=>URL.$hash); } public function handleHash($hash,$url) { $path = ROOT.DS.'data'.DS.$hash.DS.$hash; $type = getExtensionOfFilename($hash); switch($type) { case 'jpeg': case 'jpg': header ("Content-type: image/jpeg"); readfile($path); break; case 'png': header ("Content-type: image/png"); readfile($path); break; case 'gif': header ("Content-type: image/gif"); readfile($path); break; case 'webp': header ("Content-type: image/webp"); readfile($path); break; } } }