Buyrun hocam


<?php
//
//   CF Image Hosting Script v1.3
//   -------------------------------
//
//   Author:    codefuture.co.uk
//   Version:   1.3
//   Date:      26-Apr-10
//
//   download the latest version from - http://codefuture.co.uk/projects/imagehost1.3/
//   Copyright (c) 2010 codefuture.co.uk
//
////////////////////////////////////////////////////////////////////////////////////

    include_once('inc/config.php');


    if(!$settings['SET_DIS_UPLOAD'] && !checklogin()){
        header('Location: index.php');
        exit();
    }
    
////////////////////////////////////////////////////////////////////////////////////
// UPLOAD CODE START

// see if user is banned
    $db_ban = new array_db($ADD_DB_BAN);
    if ($db_ban->item_exists('ip',$_SERVER['REMOTE_ADDR']))
        $Err .= 'Sorry but you are banned from uploading images to this site.<br/>';

    elseif($_SERVER['REQUEST_METHOD'] == 'POST' && $_FILES['file']['name'][0] !=''){

        include("lib/resize.class.php");
        $img_posted ='';

        for($i=0; $i < count($_FILES['file']['name']);$i++){

            $file_name        = $_FILES['file']['name'][$i];
            $file_tmp_name    = $_FILES['file']['tmp_name'][$i];
            $file_size        = $_FILES['file']['size'][$i];
            $file_type        = strtolower($_FILES['file']['type'][$i]);
            $get_img         = @getimagesize($file_tmp_name);
            $path_info        = pathinfo($file_name);
            $err_get_img    = false;

        //min size(pixels)
            if ($get_img[0] < $IMG_MIN_SIZE || $get_img[1] < $IMG_MIN_SIZE ){
                $err_get_img = true;
                $Err.='Sorry the image size is to small,'.$IMG_MIN_SIZE.'x'.$IMG_MIN_SIZE.' is the min size allowed.<br/>';;
            }

        // max size(pixels)
            if ($get_img[0] > $IMG_MAX_SIZE || $get_img[1] > $IMG_MAX_SIZE ){
                $err_get_img = true;
                $Err.='Sorry the image size is to big,'.$IMG_MAX_SIZE.'x'.$IMG_MAX_SIZE.' is the Max size allowed.<br/>';
            }

        //Check file size (kb)
            if($file_size >= $settings['SET_MAXSIZE']) {
                $err_get_img = true;
                $Err .= 'Only images under '.format_size($settings['SET_MAXSIZE']).' are accepted for upload<br/>';
            }

        //check file type
            if (!(in_array(strtolower($path_info['extension']), $accepted)) || !(in_array($file_type, $acceptedtyp))){
                $err_get_img = true;
                $Err .=  'Only '.$types.' images are accepted for upload<br/>'; // bebug file type strtolower($_FILES["file"]["type"])
            }

            if(!$err_get_img) {
        
            //new random name
                $newname = rand(0,16).time().rand(0,16);

            //random delete ID
                $delete_id = md5(rand(0,7).rand(0,7).time().rand(0,14));

            //Image address
                $IMG_NAME = $newname.'.'.$path_info['extension'];
                $IMG_ADDRESS = $DIR_IMAGE.$IMG_NAME;

            //Thumb address
                $THUMB_NAME = $newname.'.'.$THUMB_SAVE_EXT;
                $THUMB_ADDRESS = $DIR_THUMB.$THUMB_NAME;
                $THUMB_MID_ADDRESS = $DIR_THUMB_MID.$THUMB_NAME;

            //Attempt to move the uploaded file to the upload folder
                if (@move_uploaded_file($file_tmp_name,$IMG_ADDRESS)) {

                // alt text
                    $alt = empty($_POST["alt"][$i]) ? $path_info['filename']:removeSymbols(input($_POST["alt"][$i]));

                if (isset($_POST['shorturl']) && $_POST['shorturl'] == 1 && $settings['SET_SHORT_URL_ON']){
                    $shorturl = shorturl_url('http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'?di='.$newname);
                }else{
                    $shorturl = null;
                }

                // save image info to db
                    $NEW_IMG_ITEM = array(    'id'        => $newname,
                                            'name'        => $file_name,
                                            'alt'        => $alt,
                                            'added'        => time(),
                                            'ext'        => $path_info['extension'],
                                            'ip'        => $_SERVER['REMOTE_ADDR'],
                                            'size'        => $file_size,
                                            'deleteid'    => $delete_id,
                                            'thumbsize' => @filesize($THUMB_MID_ADDRESS),
                                            'sthumbsize'=> @filesize($THUMB_ADDRESS),
                                            'private'    => (isset($_POST['private'])?1:0),
                                            'shorturl'    => $shorturl,
                                            );

                        $db = new array_db($ADD_DB_IMG);
                        if($db->add_row($NEW_IMG_ITEM) && $db->save_db_now()){

                    // thumb
                        $resizeObj = new resize($IMG_ADDRESS);
                    // make thumb
                        $resizeObj -> resizeImage($THUMB_MID_MAX_WIDTH, $THUMB_MID_MAX_HEIGHT, $THUMB_MID_OPTION);
                        $resizeObj -> imageSaveQuality($THUMB_MID_QUALITY);
                        $resizeObj -> saveImage($THUMB_MID_ADDRESS);
                    // make small thumb
                        $resizeObj -> resizeImage($THUMB_MAX_WIDTH, $THUMB_MAX_HEIGHT, $THUMB_OPTION);
                        $resizeObj -> imageSaveQuality($THUMB_QUALITY);
                        $resizeObj -> saveImage($THUMB_ADDRESS, $THUMB_QUALITY);

                    // Page var
                        $linkurl        = get_thumb_address($newname,"pt");
                        $thumb_url        = get_thumb_address($newname,"dt");
                        $thumb_mid_link    = get_thumb_mid_address($newname,"pm");
                        $thumb_mid_url    = get_thumb_mid_address($newname,"dm");
                        $imgurl            = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'?di='.$newname;
                    //    $shorturl        = $db->fetch_value('id',$img_id,'shorturl');
                        $bookmarking    = bookmarking(($shorturl !=null?$shorturl:$thumb_mid_link),$alt);
                        $open_panel        = ($settings['SET_PANEL_OPEN'] ? ' open':'');

                    // Page output
                        $img_posted .= '
                        <div class="img_box"><a href="'.$imgurl.'" title="'.$alt.'" ><img src="'.$thumb_mid_url.'" alt="Uploaded Picture" /></a></div>
                        <div class="flip">Show/Hide Links</div>
                        <div class="panel'.$open_panel.'">
                        <div class="code_box"><label id="toplabel">Social Networks:</label>'.$bookmarking.'</div>';
                    if ($shorturl != null && !empty($shorturl)){
                        $img_posted     .= '
                        <div class="code_box"><label for="shorturl">Short URL</a> (Twitter):</label> <input type="text" id="codehtml" value="'.$shorturl.'" onclick="javascript:this.focus();this.select();" readonly="true" class="text_input long" /></div>';
                    }
                        $img_posted     .= '
                        <h3>Small Thumbnail link</h3>
                                <div class="code_box"><label for="codelbb">BBCode (Forums):</label> <input type="text" id="codelbb" value="[IMG]'.$thumb_url.'[/IMG]" onclick="javascript:this.focus();this.select();" readonly="true" class="text_input long" /></div>
                                <div class="code_box"><label for="codehtml"><a href="'.$linkurl.'" title="'.$alt.'" >HTML Code</a> (Myspace):</label> <input type="text" id="codehtml" value=\'&lt;a href="'.$linkurl.'" title="'.$alt.'" &gt;&lt;img src="'.$thumb_url.'" alt="'.$alt.'" /&gt;&lt/a&gt;\' onclick="javascript:this.focus();this.select();" readonly="true" class="text_input long" /></div>
                            <h3>Thumbnail link</h3>
                                <div class="code_box"><label for="codelbb">BBCode (Forums):</label> <input type="text" id="codelbb" value="[IMG]'.$thumb_mid_url.'[/IMG]" onclick="javascript:this.focus();this.select();" readonly="true" class="text_input long" /></div>
                                <div class="code_box"><label for="codehtml"><a href="'.$thumb_mid_link.'" title="'.$alt.'" >HTML Code</a> (Myspace):</label> <input type="text" id="codehtml" value=\'&lt;a href="'.$thumb_mid_link.'" title="'.$alt.'" &gt;&lt;img src="'.$thumb_mid_url.'" alt="'.$alt.'" /&gt;&lt/a&gt;\' onclick="javascript:this.focus();this.select();" readonly="true" class="text_input long" /></div>
                            <h3>Direct link (Fullsize)</h3>
                                <div class="code_box"><label for="codebb">BBCode (Forums):</label> <input type="text" id="codebb" value="[IMG]'.$imgurl.'[/IMG]" onclick="javascript:this.focus();this.select();" readonly="true" class="text_input long" /></div>
                                <div class="code_box"><label for="codedirect">Direct Link (email &amp; IM):</label> <input type="text" id="codedirect" value="'.$imgurl.'" onclick="javascript:this.focus();this.select();" readonly="true" class="text_input long" /></div>
                            <h3>Delete Image</h3>
                                <div class="code_box"><label for="deletecode">Image Delete URL:</label> <input type="text" id="deletecode" value="'.$settings['SET_SITEURL'].'?d='.$delete_id.'" onclick="javascript:this.focus();this.select();" readonly="true" class="text_input long" /></div>
                                <p class="teaser">Use this link to remove your image at any time.</p>
                        </div>';

    // Errors -------------------
                    }else //Saving DB
                        $Err .= 'A problem occurred during saving of the database!<br/>';
                }else // move the uploaded file
                    $Err .= 'A problem occurred during file upload!<br/>';
            }//name
        }//for
    }

// UPLOAD CODE END
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// MAKE PAGE

    $menu='';
    include_once('header.php');
    error_note($Err);
    echo (isset($img_posted)? $img_posted:error_note('Sorry can not find image to upload!'));
    include_once('footer.php');

// MAKE PAGE END
////////////////////////////////////////////////////////////////////////////////////
?>