Parašė iSty· 2009 Lie. 13 22:07:30
#37
Na vat, jau
www.up.csworld.xz.lt veikia, tačiau kai paspaudi: Dokumentu sąrašas, meta kažkokį errorą..
WTF?
Config.php:
<?
$file_types_array = array('jpg','png','gif','bmp','zip','rar','exe'); //nurodykite formatus pvz array("jpg","png","gif")
$max_file_size = '25728640'; //maximalus idedamo dokumento dydis baitais 10MB = 1024 * 1024 * 10
$upload_dir = '/up'; //nurodykite direktorija kur bus dedami failai
$file_expire = '5000'; //nurodykite kiek dienu failas gules serveryje (nenaudojami failai trinami)
$max_downloads = '200'; //nurodykite max parsisiuntimu skaiciu per valanda
$gd = 'gd2'; //Gali buti GD2 arba GD1 pagal nutylejima gd2
$size_w = '220'; //Miniatūros plotis
$size_h = '165'; //miniatūros aukštis
ini_set('post_max_size', '15728640'); //Nekeisk
ini_set('upload_max_filesize', '15728640'); //Nekeisk
ini_set('max_execution_time', '31457280' ); //Nustatom iki 1h.
//Admin prisijungimas
$vardas = 'Sty';
$koduoti_md5 = 'ne'; //Jei norite uzkoduoti savo slaptazodi md5 hashu yrasykite 'taip' o jei ne tai 'ne'
$slaptazodis = 'manopw'; //slaptazodis koduotas md5 hashu - kuris reiskia 'admin'
//FTP nustatymai
$tipas = 'ftp'; //nurodykite siuntimo tipa 'html' arba expertams 'ftp'
$ftp_user_name = 'mrsty'; //ftp prisijungimo vardas
$ftp_user_pass = 'manopw'; //ftp prisijungimo slaptazodis
$ftp_server = 'gama.bendras.com'; //irasykite savo ftp hosta
$ftp_dir = 'up.csworld.xz.lt/up/'; //irasykite tikra ftp direktorija kur desi faila
//Svetaines adresui nustatyti - neliesk nebent zinai ka darai
$hostas1 = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$hostas2 = strrchr($hostas1, "/");
$hostas = substr($hostas1,0,(strlen($hostas1) - strlen($hostas2)));
$hostas = str_replace("\r","\r",str_replace("\n","\n",str_replace("\t","\t",$hostas)));
$location = $hostas."/";
?>
funkcijos.php:
<?php
if (!isset($_SESSION)) {
session_start();
}
if (isset($_SESSION['adminas'])) { define("ADMIN",TRUE); }
else { define("ADMIN",FALSE); }
if ((isset($_GET['logout'])) && ($_GET['logout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['adminas'] = NULL;
unset($_SESSION['adminas']);
echo "<script>document.location.href='".$_SERVER['PHP_SELF']."'</script>";
}
define("QUOTES_GPC", (ini_get('magic_quotes_gpc') ? TRUE : FALSE));
function baitai($size,$digits=2,$dir=false) {
$kb=1024; $mb=1024*$kb; $gb=1024*$mb; $tb=1024*$gb;
if (($size==0)&&($dir)) { return " Nulis"; }
elseif ($size<$kb) { return $size." Baitai"; }
elseif ($size<$mb) { return round($size/$kb,$digits)." Kb"; }
elseif ($size<$gb) { return round($size/$mb,$digits)." Mb"; }
elseif ($size<$tb) { return round($size/$gb,$digits)." Gb"; }
else { return round($size/$tb,$digits)." Tb"; }
}
function tipas($failas) {
$galune = explode(".",$failas);
//skaiciuojam kiek viso yra po tasko yrasu
$kiek = count($galune);
//gra˛inam paskutini iraša
return $galune[$kiek - 1];
}
function trimlink($text, $length) {
$dec = array("\"", "'", "\\", '\"', "\'", "<", ">");
$enc = array(""", "'", "\", """, "'", "<", ">");
$text = str_replace($enc, $dec, $text);
if (strlen($text) > $length) $text = substr($text, 0, ($length-3))."...";
$text = str_replace($dec, $enc, $text);
return $text;
}
function tipai($file_types_array) {
return implode( ', ', $file_types_array);
}
function tikrinam($folder, $filter, $file_expire) {
//$res = array();
//$filter = explode("|", $filter);
//$temp = opendir($folder);
//while ($file = readdir($temp)) {
// if (!in_array($file, $filter)) {
// if (!is_dir($folder.$file)) {
// if ((time() - fileatime($folder.$file)) > (60*60*24*$file_expire)) { trink($folder.$file); }
// }
// }
//}
//closedir($temp);
}
//grazina failu masyva, naudokite filtrus
function failai($dir, $filter,$tipas='failai', $rusiuoti=true) {
global $file_expire;
$failai = array(); //"$failai" kintamaji verciam i masyva
$filter = explode("|", $filter);
if (is_dir($dir)) { $d = opendir($dir); } //jeigu nurodyta direktorija egzistuoja
else { //kitu atveju metam klaidos pranesima
user_error("<b><font color=red>Folderio klaida</font></b>");
exit;
}
while (false !== ($failas = readdir($d))) { //Paleidziame cikla
//Jeigu tai dokumentas ir jis nera filtru sarase - tesiam veiksma
if ($failas != "." && $failas != "..") {
if (is_file($dir.$failas) && !in_array($failas, $filter) && $tipas == 'failai') {
$a = explode(".",basename($failas)); //suskaldom failo pavadinima pagal taskus
$ext = $a[count($a) - 1]; //nustatom failo tipa
$vardas = str_replace('.'.$ext,'',basename($failas)); //patvarkom dokumento pavadinima
//jei dokumento galiojimo laikas tuoj baigsis ji pazymim
if ((time() - fileatime($dir.$failas)) > (60*60*24*$file_expire)) { $pazymetas = "taip"; }
else { $pazymetas = "ne"; }
$failai[] = array( //talpiname informacija i ARRAY - masyva
'failas' => $failas, //pilnas dokumento pavadinimas
'galioja' => fileatime($dir.$failas), //kada paskutini karta ziuretas
'sukurtas' => filemtime($dir.$failas), //kada sukurtas
'pazymetas' => $pazymetas,
'dydis' => filesize($dir.$failas), //dokumento dydis baitais
'vardas' => $vardas, //dokumento pavadinimas skirtas saugiam atvaizdavimui
'tipas' => $ext //dokumento pletinys
);
}
if (is_dir($dir.$failas) && $tipas != 'failai' && !in_array($failas, $filter)) {
$failai[] = array(
'vardas' => $dir.$failas,
'name' => $failas,
'sukurtas' => filemtime($dir.$failas)
);
}
}
}
if ($rusiuoti == true) {
$kiek = count($failai); //suzinau kiek yra irasu MASYVE $failai
if ($kiek) { //jeigu masyvas netuscias
foreach ($failai as $key => $row) {
$laikas[$key] = $row['sukurtas']; //rusiuojam pagal sukurimo data
}
array_multisort($laikas,SORT_DESC,$failai);
}
}
return $failai;
}
function folderiai($folder, $filter) {
$filter = explode("|", $filter);
$res = array();
$temp = opendir($folder);
while ($file = readdir($temp)) {
if (is_dir($file) && !in_array($file, $filter)) $res[] = "$file/";
}
closedir($temp);
return $res;
}
function listas($failai) {
global $upload_dir, $location, $file_expire, $dydis;
$res = "";
for ($i=0;$i < count($failai);$i++) {
if ((time() - fileatime($upload_dir.$failai[$i]['failas'])) > (60*60*24*$file_expire)) { trink($failai[$i]['failas']); }
else {
$sel = (($failai[$i]['pazymetas'] == "taip") ? " class=\"pazymetas\"" : "");
if (ADMIN) { $admin = "<a href='?del=".urlencode($failai[$i]['failas'])."' onclick=\"if (confirm('Ar tikrai nori trinti ".urlencode($failai[$i]['failas'])."?')) return true; else return false;\"><img src='images/trinti.gif' border='0'></a>"; }
else { $admin = ''; }
if (is_file("tmb/".$failai[$i]['failas']."")) { $img = "<br><center><img src=\"tmb/".urlencode($failai[$i]['failas'])."\" border=\"1\"></center><br />"; } //elseif (isimage($upload_dir.$failai[$i]['failas'])) { trumb($upload_dir.$failai[$i]['failas'],$size_w,$size_h,"tmb/".$failai[$i]['failas'].""); $img = ''; }
else { $img = ''; }
$res .= "
<tr ".$sel.">
<td align='center'><img src='images/".$failai[$i]['tipas'].".gif'></td>
<td>$admin <a href='".$location."index.php?file=".urlencode($failai[$i]['failas'])."' title='
header=[ <img style=\"vertical-align:middle\" src=images/".$failai[$i]['tipas'].".gif> ".urlencode(trimlink($failai[$i]['failas'],20))."]
body=[$img
<STRONG>Naudotas</STRONG>: (".date("Y m d",$failai[$i]['galioja']).")<BR>
<STRONG>Galioja iki</STRONG>: (".date("Y m d",($failai[$i]['galioja'] + (60*60*24*$file_expire))).")<BR>
<STRONG>Dydis</STRONG>: (".baitai($failai[$i]['dydis']).")
] cssheader=[tips_head] cssbody=[tips_body] fade=[on]'>".trimlink($failai[$i]['vardas'],20)."</a></td>
<td>".baitai($failai[$i]['dydis'])."</td>
</tr>\n";
$dydis = $dydis + $failai[$i]['dydis'];
}
//define($dydis,$dydis);
}
return $res;
}
function get_user_os() {
global $global_info, $HTTP_USER_AGENT, $HTTP_SERVER_VARS;
if (!empty($global_info['user_os'])) {
return $global_info['user_os'];
}
if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
$HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
}
elseif (getenv("HTTP_USER_AGENT")) {
$HTTP_USER_AGENT = getenv("HTTP_USER_AGENT");
}
elseif (empty($HTTP_USER_AGENT)) {
$HTTP_USER_AGENT = "";
}
if (eregi("Win", $HTTP_USER_AGENT)) {
$global_info['user_os'] = "WIN";
}
elseif (eregi("Mac", $HTTP_USER_AGENT)) {
$global_info['user_os'] = "MAC";
}
else {
$global_info['user_os'] = "OTHER";
}
return $global_info['user_os'];
}
function get_browser_info() {
global $global_info, $HTTP_USER_AGENT, $HTTP_SERVER_VARS;
if (!empty($global_info['browser_agent'])) {
return $global_info['browser_agent'];
}
if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
$HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
}
elseif (getenv("HTTP_USER_AGENT")) {
$HTTP_USER_AGENT = getenv("HTTP_USER_AGENT");
}
elseif (empty($HTTP_USER_AGENT)) {
$HTTP_USER_AGENT = "";
}
if (eregi("MSIE ([0-9].[0-9]{1,2})", $HTTP_USER_AGENT, $regs)) {
$global_info['browser_agent'] = "MSIE";
$global_info['browser_version'] = $regs[1];
}
elseif (eregi("Mozilla/([0-9].[0-9]{1,2})", $HTTP_USER_AGENT, $regs)) {
$global_info['browser_agent'] = "MOZILLA";
$global_info['browser_version'] = $regs[1];
}
elseif (eregi("Opera(/| )([0-9].[0-9]{1,2})", $HTTP_USER_AGENT, $regs)) {
$global_info['browser_agent'] = "OPERA";
$global_info['browser_version'] = $regs[2];
}
else {
$global_info['browser_agent'] = "OTHER";
$global_info['browser_version'] = 0;
}
return $global_info['browser_agent'];
}
//graziai lentele su failais, galima norima faila pazymeti - pvz tuos kuriu galiojimo laikas greit baigsis
function download($file, $filter) {
global $max_downloads, $location, $global_info;
$filter = explode("|", $filter);
if (!in_array($file, $filter) && is_file($file)) {
if (touch($file)) {
$kiek = kukius();
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){
$file = preg_replace('/\./', '%2e', $file,substr_count($file, '.') - 1);
}
if (is_file($file) && ($max_downloads >= $kiek)) {
//if (is_file($file)) {
if(connection_status()==0){
if (get_user_os() == "MAC") {
header("Content-Type: application/x-unknown\n");
header("Content-Disposition: attachment; filename=\"".basename($file)."\"\n");
}
elseif (get_browser_info() == "MSIE") {
$disposition = (!eregi("\.zip$", basename($file))) ? 'attachment' : 'inline';
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Length: ' . (string)(filesize($file)));
header("Content-Disposition: $disposition; filename=\"".basename($file)."\"\n");
//header('Content-Disposition: attachment; filename=' . $fileName . '');
header("Cache-Control: cache, must-revalidate");
header('Pragma: public');
}
elseif (get_browser_info() == "OPERA") {
header("Content-Disposition: attachment; filename=\"".basename($file)."\"\n");
header("Content-Type: application/octetstream\n");
}
else {
header("Content-Disposition: attachment; filename=\"".basename($file)."\"\n");
header("Content-Type: application/octet-stream\n");
}
header("Content-Length: ".(string)(filesize($file))."\n\n");
readfile(''.$file.'');
exit;
}else{
header("location: $_SERVER[PHP_SELF]");
exit;
}
}
elseif ($kiek >= $max_downloads) {
header("HTTP/1.0 404 Not Found");
echo "<b><font size='5', color='red'>Klaida!</font></b><hr>
Pasiektas dienos limitas.<b> $max_downloads </b>Failai per 1val.";
exit;
}
else {
header("HTTP/1.0 404 Not Found");
}
}
else {
echo "<script> alert('Failo modifikacijos klaida $file')</script>";
}
}
else { header("location: $location"); }
exit;
}
function kukius() {
global $location, $max_downloads;
if ($max_downloads != 0) {
if (isset($_COOKIE["fdisk"])) { $value = $_COOKIE["fdisk"]; }
else { $value = 0; }
$value++;
setcookie("fdisk", $value);
setcookie("fdisk", $value, time()+3600); /* galioja 1 valanda */
setcookie("fdisk", $value, time()+3600, "/~fdisk/", "$location", 1);
return $value;
}
else { return 0; }
}
function upload($file_types_array=array("JPG"), $upload_dir=""){
$msg = '';
global $location, $msg, $max_file_size, $ftp_user_name, $ftp_user_pass, $ftp_server, $ftp_dir, $tipas, $size_w, $size_h;
foreach($_FILES["file"]["error"] as $key => $value) {
if($_FILES["file"]["name"][$key]!="") {
$origfilename = strip_tags($_FILES["file"]["name"][$key]);
if($value==UPLOAD_ERR_OK) {
$filename = explode(".", $_FILES["file"]["name"][$key]);
$filenameext = strtolower($filename[count($filename)-1]);
unset($filename[count($filename)-1]);
$filename = implode(".", $filename);
$filename = substr($filename, 0, 60).".".$filenameext;
$file_ext_allow = FALSE;
for($x=0;$x<count($file_types_array);$x++){
if($filenameext==$file_types_array[$x]) { $file_ext_allow = TRUE; }
} // for
if($file_ext_allow){
if($_FILES["file"]["size"][$key]<$max_file_size){
$ieskom = array("?","&","="," ","+","-","#");
$keiciam = array("","","","_","","","");
$filename = str_replace($ieskom, $keiciam, $filename);
if(is_file($upload_dir.$filename)) { $filename = time()."_".$filename; }
if ($tipas == 'ftp') {
$web_location=$upload_dir.$filename;
$destination_file=$ftp_dir.$filename;
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$upload = ftp_put($conn_id, $destination_file, $_FILES["file"]["tmp_name"][$key], FTP_BINARY);
$ch=ftp_site($conn_id,"chmod 777 ".$destination_file);
ftp_close($conn_id);
}
else {
move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$filename);
if (isimage($upload_dir.$filename)) {
trumb($upload_dir.$filename, $size_w, $size_h, "tmb/$filename");
$msg .= "<center>
<a href='".$_SERVER['PHP_SELF']."?file=".urlencode($filename)."'><img src='tmb/$filename' border=1></a>
</center><br>
bbc: <input type='text' value='[img]".$location."tmb/".$filename."[/img]' onclick='select(this)' class='inputas' size='50'><br>
"; }
}
if (file_exists($upload_dir.$filename)) {
$msg .= "Nuoroda: <a href='".$_SERVER['PHP_SELF']."?file=".urlencode($filename)."'>".$filename."</a><br />Url: <input type='text' value='".$location."?file=".urlencode($filename)."' onclick='select(this)' class='inputas' size='50'><hr /><br />";
}
else { $msg .= 'Ikelimo klaida... Dokumentas: <font color="#FF0000">'.$origfilename."</font> nebuvo ikeltas<br />"; }
}
else { $msg .= '<font color="#FF0000">'.$origfilename."</font> dokumentas perdidelis <br />"; }
} // if
else{ $msg .= '<font color="#FF0000">'.$origfilename." </font> dokumentas netinkamo pletinio <br />"; }
}
else{ $msg .= '<font color="#FF0000">'.$origfilename." </font> nebuvo nusiustas <br />"; } // else
}
}
print_r($_FILES['file']['error']);
}
function prisijungti($user,$pass) {
global $vardas, $slaptazodis, $koduoti_md5;
if ($koduoti_md5 == 'taip') {
//echo "TIKRINU PER MD \$user = $user = $vardas :: \$pass = $pass = $slaptazodis";
if ($user == $vardas && md5($pass) == $slaptazodis) {
$_SESSION['adminas'] = $user;
}
}
elseif ($koduoti_md5 != 'taip') {
if ($user == $vardas && $pass == $slaptazodis) { $_SESSION['adminas'] = $user; }
}
else {
define("ADMIN",FALSE);
}
}
function isImage($img) {
//$img = str_replace(array("?","&","="),"",$img);
list($owdt,$ohgt,$otype)=@getimagesize($img);
switch($otype) {
case 1: if (!function_exists('imagecreatefromgif')) { return false; } else { return true; } break;
case 2: if (!function_exists('imagecreatefromjpeg')) { return false; } else { return true; } break;
case 3: if (!function_exists('imagecreatefrompng')) { return false; } else { return true; } break;
case 7: if (!function_exists('imagecreatefromtif')) { return false; } else { return true; } break;
case 6: if (!function_exists('imagecreatefrombmp')) { return false; } else { return true; } break;
default: return false;
}
}
// Create a selection list from an array created by makefilelist()
function sarasas($files, $selected="") {
$res = "";
for ($i=0;$i < count($files);$i++) {
$sel = ($selected == $files[$i] ? " selected" : "");
$res .= "<option value='".$files[$i]."'$sel>".$files[$i]."</option>\n";
}
return $res;
}
//aptvarko inputa
function stripinput($text) {
if (QUOTES_GPC) $text = stripslashes($text);
$search = array("\"", "'", "\\", '\"', "\'", "<", ">", " ");
$replace = array(""", "'", "\", """, "'", "<", ">", " ");
$text = str_replace($search, $replace, $text);
return $text;
}
function trumb1($file,$maxwdt,$maxhgt,$dest) {
list($owdt,$ohgt,$otype)=@getimagesize($file);
switch($otype) {
case 1: $newimg=imagecreatefromgif($file); break;
case 2: $newimg=imagecreatefromjpeg($file); break;
case 3: $newimg=imagecreatefrompng($file); break;
case 6: $newimg=imagecreatefrombmp($file); break;
default: echo "Unkown filetype (file $file, typ $otype)"; return;
}
if($newimg) {
if($owdt>1500 || $ohgt>1200)
list($owdt, $ohgt) = Resample($newimg, $owdt, $ohgt, 1024,768,0);
Resample($newimg, $owdt, $ohgt, $maxwdt, $maxhgt);
if(!$dest) return $newimg;
if(!is_dir(dirname($dest)))
mkdir(dirname($dest));
switch($otype) {
case 1: imagegif($newimg,$dest); break;
case 2: imagejpeg($newimg,$dest,90); break;
case 3: imagepng($newimg,$dest); break;
case 6: imagewbmp($newimg,$dest); break;
}
imagedestroy($newimg);
chmod($dest,0644);
}
}
function Resample(&$img, $owdt, $ohgt, $maxwdt, $maxhgt, $quality=1) {
if(!$maxwdt) $divwdt=0;
else $divwdt=Max(1,$owdt/$maxwdt);
if(!$maxhgt) $divhgt=0;
else $divhgt=Max(1,$ohgt/$maxhgt);
if($divwdt>=$divhgt) {
$newwdt=$maxwdt;
$newhgt=round($ohgt/$divwdt);
} else {
$newhgt=$maxhgt;
$newwdt=round($owdt/$divhgt);
}
$tn=imagecreatetruecolor($newwdt,$newhgt);
if($quality)
@imagecopyresampled($tn,$img,0,0,0,0,$newwdt,$newhgt,$owdt,$ohgt);
else
@imagecopyresized($tn,$img,0,0,0,0,$newwdt,$newhgt,$owdt,$ohgt);
imagedestroy($img);
$img = $tn;
return array($newwdt, $newhgt);
}
// Photo Gallery functions by CrappoMan
function constrainImage($width,$height,$max_width,$max_height){
$img_width = '';
$img_height = '';
if (!$height||!$width||!$max_height||!$max_width) {
return false;
} elseif ($height>$max_height||$width>$max_width) {
if ($height>$width) {
if ($img_width>$max_width) {
$img_width=$max_width;
$img_height=round(($max_width*$max_height)/$img_width);
} else {
$img_width=round(($width*$max_height)/$height);
$img_height=$max_height;
}
} else {
if ($img_height>$max_height) {
$img_width=round(($max_width*$max_height)/$img_height);
$img_height=$max_height;
} else {
$img_width=$max_width;
$img_height=round(($height*$max_width)/$width);
}
}
return array('width'=>$img_width,'height'=>$img_height);
} else {
return array('width'=>$width,'height'=>$height);
}
}
function trumb($origfile,$new_w,$new_h,$thumbfile) {
global $gd;
if ($gd != 'off') {
list($owdt,$ohgt,$otype)=@getimagesize($origfile);
switch($otype) {
case 1: $origimage=@imagecreatefromgif($origfile); break;
case 2: $origimage=@imagecreatefromjpeg($origfile); break;
case 3: $origimage=@imagecreatefrompng($origfile); break;
case 7: $origimage=@imagecreatefromjpeg($origfile); break;
case 6: $origimage=imagecreatefrombmp($origfile); break;
default: $origimage=@imagecreatefromjpeg($origfile); return;
}
$origwidth=$owdt;
$origheight=$ohgt;
//echo "$owdt=\$owdt, $ohgt=\$ohgt";
$size=constrainImage($origwidth,$origheight,$new_w,$new_h);
if ($gd=="gd1") {
$thumbimage=imagecreate($new_w,$new_h);
$background=imagecolorallocate($thumbimage,255,255,255);
imagefill($thumbimage,0,0,$background);
$result=imagecopyresized($thumbimage, $origimage,round(($new_w-$size['width'])/2),round(($new_h-$size['height'])/2),0,0,$size['width'],$size['height'],$origwidth,$origheight);
} else {
$thumbimage=imagecreatetruecolor($new_w,$new_h);
$background=imagecolorallocate($thumbimage,255,255,255);
imagefill($thumbimage,0,0,$background);
$result=imagecopyresampled($thumbimage, $origimage,round(($new_w-$size['width'])/2),round(($new_h-$size['height'])/2),0,0,$size['width'],$size['height'],$origwidth,$origheight);
}
touch($thumbfile);
imageJPEG($thumbimage,$thumbfile);
}
}
function ImageCreateFromBMP($filename)
{
if (! $f1 = fopen($filename,"rb")) return FALSE;
$FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14));
if ($FILE['file_type'] != 19778) return FALSE;
$BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.
'/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
'/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1,40));
$BMP['colors'] = pow(2,$BMP['bits_per_pixel']);
if ($BMP['size_bitmap'] == 0) $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
$BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8;
$BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
$BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4);
$BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4);
$BMP['decal'] = 4-(4*$BMP['decal']);
if ($BMP['decal'] == 4) $BMP['decal'] = 0;
$PALETTE = array();
if ($BMP['colors'] < 16777216)
{
$PALETTE = unpack('V'.$BMP['colors'], fread($f1,$BMP['colors']*4));
}
$IMG = fread($f1,$BMP['size_bitmap']);
$VIDE = chr(0);
$res = imagecreatetruecolor($BMP['width'],$BMP['height']);
$P = 0;
$Y = $BMP['height']-1;
while ($Y >= 0)
{
$X=0;
while ($X < $BMP['width'])
{
if ($BMP['bits_per_pixel'] == 24)
$COLOR = unpack("V",substr($IMG,$P,3).$VIDE);
elseif ($BMP['bits_per_pixel'] == 16)
{
$COLOR = unpack("n",substr($IMG,$P,2));
$COLOR[1] = $PALETTE[$COLOR[1]+1];
}
elseif ($BMP['bits_per_pixel'] == 8)
{
$COLOR = unpack("n",$VIDE.substr($IMG,$P,1));
$COLOR[1] = $PALETTE[$COLOR[1]+1];
}
elseif ($BMP['bits_per_pixel'] == 4)
{
$COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
if (($P*2)%2 == 0) $COLOR[1] = ($COLOR[1] >> 4) ; else $COLOR[1] = ($COLOR[1] & 0x0F);
$COLOR[1] = $PALETTE[$COLOR[1]+1];
}
elseif ($BMP['bits_per_pixel'] == 1)
{
$COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7;
elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
$COLOR[1] = $PALETTE[$COLOR[1]+1];
}
else
return FALSE;
imagesetpixel($res,$X,$Y,$COLOR[1]);
$X++;
$P += $BMP['bytes_per_pixel'];
}
$Y--;
$P+=$BMP['decal'];
}
fclose($f1);
return $res;
}
function trink($failas) {
global $upload_dir;
if (is_file($upload_dir.'/'.$failas)) {
unlink($upload_dir.'/'.$failas);
}
if (is_file('tmb/'.$failas.'')) {
unlink('tmb/'.$failas.'');
}
//return "<script>document.location.href='".$_SERVER['PHP_SELF']."'</script>";
}
?>