Skip to content

Instantly share code, notes, and snippets.

@EhabElzeny
Last active June 27, 2018 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EhabElzeny/60a539f6ccd87ff573da9a7a7a57851e to your computer and use it in GitHub Desktop.
Save EhabElzeny/60a539f6ccd87ff573da9a7a7a57851e to your computer and use it in GitHub Desktop.
it's simple file up for learn made from oop class
<?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