0xyGen Posted August 24, 2009 Share Posted August 24, 2009 Hi everybody, im coding a smilar php thumbnail class on php5 but i have a problem. i cant access public variable. my codes class thumbnail { private $tmp; private $ul_dir; private $thumbdir; public $filetypes = 'jpg,jpeg,gif,png'; public $renamefile; public $rename; public $errors = array(); public Function __construct($temp,$upload_dir,$thumb_dir,$t_name,$_name) { $this->tmp = $temp; $this->ul_dir = $upload_dir; $this->thumbdir = $thumb_dir; //*****LOOK THIS echo $this->rename; echo $this->renamefile; //****** if(!is_dir($this->tmp)) { $this->errors[] = 'Bu Dizin Kullanılabilir Değil : <b>'. $this->tmp . '</b>'; } elseif(!is_dir($this->ul_dir)) { $this->errors[] = 'Bu Dizin Kullanılabilir Değil : <b>'. $this->ul_dir . '</b>'; } elseif(!is_dir($this->thumbdir)) { $this->errors[] = 'Bu Dizin Kullanılabilir Değil : <b>'. $this->thumbdir . '</b>'; } else { $this->_upload($t_name,$f_name); } } public Function _upload($tmp_name,$file_name) { if($this->renamefile) { echo 'if'; $file_name = $this->rename; } else { echo 'else'; $file_name = substr(md5(uniqid((double)microtime()*1000000)),0,10); } $filetype = $this->checkfiletypes($file_name); if(!preg_match("/($filetype)$/",$file_name)) { $this->errors[] = 'Desteklenmeyeden Dosya Biçimi'; return false; } /* if(move_uploaded_file($tmp_name,$this->tmp.'/'.$file_name)) { return true; } */ } private Function checkfiletypes($filetype) { $filetype = explode(',',$filetype); $filetype = implode('|',$filetype); return $filetype; } public Function getmessage() { echo '<ul>'; foreach($this->errors as $error) { echo '<li>'.$error.'</li>'; } echo '</ul>'; } } if(isset($_POST['submit'])) { //print_r($_FILES); $img = new thumbnail('temp','upload','upload/thumb',$_FILES['dosya']['tmp_name'],$_FILES['dosya']['name']); $img->renamefile = TRUE; $img->rename = "0xyGen.jpg"; $img->getmessage(); } ?> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="dosya"> <input type="submit" name="submit" value="submit"> </form> i seted $img->rename = TRUE; but write on class then upload a example.jpg output is a blank. Quote Link to comment https://forums.phpfreaks.com/topic/171632-php5-class-not-acces-public-variable/ Share on other sites More sharing options...
wildteen88 Posted August 24, 2009 Share Posted August 24, 2009 Echo'ing the rename or renamefile class variable within your constructor wont display anything as these variables are set after you have created a new instance of your thumbnail class. Remember the constructor is called when you create a new instance of your class, This is how you're calling your class. $img = new thumbnail('temp','upload','upload/thumb',$_FILES['dosya']['tmp_name'],$_FILES['dosya']['name']); After that line you're then setting your class variables $img->renamefile = TRUE; $img->rename = "0xyGen.jpg"; Quote Link to comment https://forums.phpfreaks.com/topic/171632-php5-class-not-acces-public-variable/#findComment-905193 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.