如何在类中使用全局变量

时间:2014-11-23 21:39:51

标签: php class

我想在类中使用class.upload.php变量的pre选项。因为我在所有上传页面中重复设置,当我想做一点改变时我必须改变所有这些变量,我需要一个解决方案,我可以将这个预选作为变量或函数或_construct添加.. < / p>

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;}

                  }

   }

如何让这些全局变量在我的所有页面中再次使用。

  //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

2 个答案:

答案 0 :(得分:1)

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>'; }
}
}

答案 1 :(得分:0)

您可以将它们放在$ _SESSION变量

或者创建一个get函数并返回那些变量