Bagova
Bagova

Reputation: 161

How to use global variables in a class

I want to use pre options of class.upload.php variables in the class. Becuse i repeat thiş setting in all of my upload pages and when i wan to make a little change i must change all of this variables , i need a solution that i can add this preoptions as a variable or as a function or _construct..

if ((isset($_POST['actionmanset']) ? $_POST['actionmanset'] : (isset($_GET['actionmanset']) ?   $_GET['actionmanset'] : '')) == 'manset')
{

 $handle = new Upload($_FILES['resim']);

if ($handle->uploaded) {

     //common variables i want to use start
    $handle->auto_create_dir  = FALSE;
    $handle->file_max_size = '5000000'; // 4mb
    $handle->mime_check    = TRUE; #Güvenlik
    $handle->allowed = array('image/jpeg','image/gif','image/png'); #Güvenlik Yalnız resim
    $handle->no_script = true; #güvenlik
    $handle->image_resize          = true;
    $handle->image_ratio_crop      = true;
    $handle->file_auto_rename = true; 
    $handle->file_name_body_pre = 'tt_';
    //common variables i want to use finish

    $handle->image_x               = 427;
    $handle->image_y               = 225;
    $handle->Process('../uploads/manset/');
    if ($handle->processed) { $mansetresmi=$handle->file_dst_name;}

                  }

   }

how can i keep this global variables to use again in all my pages.

  //common variables i want to use start
    $handle->auto_create_dir  = FALSE;
    $handle->file_max_size = '5000000'; // 4mb
    $handle->mime_check    = TRUE; #Güvenlik
    $handle->allowed = array('image/jpeg','image/gif','image/png'); #Güvenlik Yalnız resim
    $handle->no_script = true; #güvenlik
    $handle->image_resize          = true;
    $handle->image_ratio_crop      = true;
    $handle->file_auto_rename = true; 
    $handle->file_name_body_pre = 'tt_';
    //common variables i want to use finish

Upvotes: 0

Views: 123

Answers (2)

Milad
Milad

Reputation: 28592

Class GlobalsTT{
    public $auto_create_dir  = FALSE;
    public $file_max_size = '5000000'; // 4mb
    public $mime_check    = TRUE; #Güvenlik
    public $allowed = array('image/jpeg','image/gif','image/png'); #Güvenlik Yalnız resim
    public $no_script = true; #güvenlik
    public $image_resize          = true;
    public $image_ratio_crop      = true;
    public $file_auto_rename = true; 
    public $file_name_body_pre = 'tt_';

    public function set($variable_name,$value){

         $this-$variable_name = $value ; 

     }

   public function get($variable_name){

     return $this->$variable_name;

   }

  }

if ((isset($_POST['actionmanset']) ? $_POST['actionmanset'] : (isset($_GET['actionmanset']) ? $_GET['actionmanset'] : '')) == 'manset') {
ichbar($_FILES["resim"]["name"]);
$handle = new Upload($_FILES['resim']);

if ($handle->uploaded) {
    //Orjinal Dosya
    $globals = new GlobalsTT();
    $handle->image_x               = 427;
    $handle->image_y               = 225;
    $handle->Process('../uploads/manset/');

   //145 lık thumbnail
    $globals = new GlobalsTT();
    $handle->image_x               = 145;
    $handle->image_y               = 76;
    $handle->Process('../uploads/manset/145/');

    $thumb_result = $handle->processed;
    $thumb_width = $handle->image_dst_x;
    $thumb_height = $handle->image_dst_y;

if   ($handle->processed) { $mansetresmi=$handle->file_dst_name;} 
    else { $err='Resminiz sadece jpg, png ya da gif formatında ve maksimum 4 mb büyüklüğünde olmalıdır. Detaylı Hata Ayrintisi:' . $handle->error . '';
    echo '<script type="text/javascript">alert("'.$err.'");</script>'; }
}
}

Upvotes: 1

Rob Michiels
Rob Michiels

Reputation: 134

You can put them in a $_SESSION variable

Or create a get function and return those variables

Upvotes: 0

Related Questions