Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Przejście parametrów przez __set
Yhy
post
Post #1





Grupa: Zarejestrowani
Postów: 22
Pomógł: 1
Dołączył: 10.10.2011

Ostrzeżenie: (0%)
-----


Mam następny problem, fragment kodu -

  1. class Avatar{
  2.  
  3. public $file_size;
  4. public $file_type;
  5. public $file_tmp;
  6. public $file_name;
  7.  
  8. function __set($name, $value){
  9. if( ($name = "file_size") && ($value < 20000)){
  10. return $this->file_size = $value;
  11. }
  12. elseif( ($name = "file_type") && ($value == "image/jpeg" or "image/png")){
  13. return $this->file_type = $value;
  14. }
  15. else{
  16. echo 'Plik nie spełnia wymagań.';
  17. }
  18. }
  19.  
  20. public function upload(){
  21.  
  22. if( move_uploaded_file($this->file_tmp, "avatars/$this->file_name")){
  23. echo 'Plik został zauploadowany.';
  24. }
  25.  
  26.  
  27. }
  28.  
  29. }


  1. <?php
  2.  
  3. echo '<form action="#" method="POST" enctype="multipart/form-data">
  4. <input type="file" name="avatar">
  5. <input type="submit" name="submit" value="Wgraj">
  6. </form>';
  7.  
  8. if( isset($_FILES['avatar'])){
  9.  
  10. include('class.Avatar.php');
  11.  
  12. $avatar = new Avatar;
  13.  
  14. $avatar->$file_size = $_FILES['avatar']['size'];
  15. $avatar->file_tmp = $_FILES['avatar']['tmp_name'];
  16. $avatar->file_name = $_FILES['avatar']['name'];
  17.  
  18. $avatar->upload();
  19. }
  20.  
  21.  
  22. ?>


Błąd:

Cytat
Notice: Undefined variable: file_size in index.php on line 32
Plik został zauploadowany.


Problem - nie widzę błędu, ponieważ z tego co wiem znak dolara powodu przefiltrowanie parametru przez funkcję __set. Ponadto plik którzy wrzucam jest zbyt duży, więc powinien zostać odrzucony.

Ten post edytował Yhy 10.10.2011, 15:24:48
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 09:21