Php oop (__construct) file upload
05:49 09 Dec 2019

I work on a oop class.php file. I want to implement function __construct(). I don't know why it doesn't work.

I think there is error, but I don't know how to write it. $args['file_upload'] = $_FILES['file_upload'][''] ?? NULL;

Thanks.

fileupload.class.php

public function __construct($string){
    $this->filename      = $_FILES['$string']['name']['0']; 
    $this->temp_path     = $_FILES['$string']['tmp_name']['0'];
    $this->type      = $_FILES['$string']['type']['0'];
    $this->size      = $_FILES['$string']['size']['0'];

}   
public function create() {
       if(move_uploaded_file....
}

fileupload.php

if(is_post_request()) {
        
        //Create record using post parameters
        $args = [];
        $args['prod_name'] = $_POST['prod_name'] ?? NULL;
        $args['file_upload'] = $_FILES['file_upload'][''] ?? NULL;
        
        $image = new Imageupload($args);
        $result = $image->create();

          if($result === true) {
            $new_id = $image->id;
            $_SESSION['message'] = 'The image was uploaded.';
          } else {
            // show errors
          }
        } else {
          // display the form
          $image = [];
        }

Product name:

UPDATE1 function works

public function add_files() {
        
    $this->filename     = $_FILES['file_upload']['name']['0'];  
    $this->temp_path    = $_FILES['file_upload']['tmp_name']['0'];
    $this->type         = $_FILES['file_upload']['type']['0'];
    $this->size         = $_FILES['file_upload']['size']['0'];
}

$image = new Imageupload($args);
$image->add_files();
php mysql