Last active
June 27, 2018 01:08
-
-
Save EhabElzeny/60a539f6ccd87ff573da9a7a7a57851e to your computer and use it in GitHub Desktop.
it's simple file up for learn made from oop class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class upload{ | |
public $file ; | |
public $error ; | |
public $messge_error ; | |
public $extension ; | |
protected $dirold ; | |
private $new_dir ; | |
const welecome = 'welecome here in any time >>>>' ; | |
public function upload_file ($support,$error){ // two agrment support is array types support and error array errors $_files | |
if (isset($_FILES['upload_file'])){ | |
if (in_array($this->extension,$support) === true ){ // is condition for search in array and return to ture if extension is support | |
$this->dirold = $_FILES['upload_file']['tmp_name'] ; | |
$this->new_dir = __dir__.'/upload/'. $_FILES['upload_file']['name'] ; | |
move_uploaded_file ($this->dirold,$this->new_dir); | |
return $this->messge_error[$this->error] = $this->messge_error[$error] . '<br />' . self::welecome . $this->new_dir ; | |
}elseif(in_array($this->extension,$support) === false ){ // but this condition for not support iam search in array extension | |
if ($this->error == 0){ | |
if (unlink($_FILES['upload_file']['tmp_name']) === true ){ | |
return die('the file upload and remove because not support '). $this->extension; | |
} | |
} | |
return $this->messge_error[$this->error] = $this->messge_error [$error] . 'the not' . '<br />' . self::welecome; // return messge error | |
} | |
} else { | |
echo 'SET YOUR FILE TO UPLOAD NOW TIME IS ' . date('h:i:s') ; | |
} | |
} | |
} | |
$file = new upload; | |
@$error = $file->error = $_FILES['upload_file'] ['error']; | |
@$file->extension = strstr($_FILES['upload_file'] ['name'], '.') ; | |
@$support =array('.png' ,'.jpg','.jpeg','.PNG','.JPG','.JPEG' ); | |
$file->messge_error = array( | |
'تم تحميل الملف بنجاح' , | |
'الملف اكبر من الحجم المتاح للرفع', | |
'الملف اكبر من الحجم المتاح للرفع', | |
'UPLOAD_ERR_PARTIAL', | |
'الملف لم يتم رفعه', | |
'UPLOAD_ERR_NO_TMP_DIR', | |
'UPLOAD_ERR_CANT_WRITE', | |
'UPLOAD_ERR_EXTENSION' | |
) ; | |
echo $file->upload_file($support,$error ) ; | |
@print_r($_FILES['upload_file']) ; | |
?> | |
<form action="up.php" method="POST" enctype="multipart/form-data" dir="rtl"> | |
<input type="file" name="upload_file"> | |
<input type="submit" name="OK"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment