hei, php oop file upload, update script function. size check function , extension check function. somewhere go wrong extension check function.
<?php class upload{ public $src = "upload/"; public $tmp; public $filename; public $typefl; public $uploadfile; public $type = array("php", "css", "js", "html", "htm", ".php"); function __construct(){ $this -> filename = $_files["file"]["name"]; $this -> tmp = $_files["file"]["tmp_name"]; $this -> uploadfile = $this -> src . basename($this -> filename); } public function sizeck(){ if($_files["file"]["size"] > 50000000){ echo "fisier prea mare"; return true; } } public function extens(){ $this -> typefl = pathinfo($this -> tmp, pathinfo_extension); if(in_array($this -> typefl, $this -> type)){ echo "fisier nepermis!!!"; return false; } else{ return true; } } public function uploadfile(){ if(move_uploaded_file($this -> tmp, $this -> uploadfile)){ return true; } } } ?> and call upload :
<?php if(isset($_files['file'])){ $fileupload = new upload(); if(!$fileupload -> sizeck()){ if(!$fileupload -> extens()){ if($fileupload -> uploadfile()){ echo 'fisierul fost uploadat'; } } } } ?> where wrong , why??
your if statement has !, means it's true if extens() returns false.
but wan't move on, if it's true. remove !.
if(!$fileupload -> extens()){ should
if($fileupload -> extens()){ and can't extension form tmp_name. should name. tmp_name doesn't have extension in it's name.
so change
$this -> tmp = $_files["file"]["tmp_name"]; to
$this -> tmp = $_files["file"]["name"];
Comments
Post a Comment