[ظƒظ„ط§ط³] upload ظ„ظ„ط±ظپط¹



بسم الله الرحمن الرحيم


ايه اخباركم ؟؟
انا لسه مخلص كلاس الupload و الكلاس ده جزء من الframework قررت تطرح هنا مجانا و ان شاء الله راح تكون اول framework عربي و يا ريت لو في حد بيعرف يحلل
انا محتاج مساعدة في التحليل

و بس الكلاس اهه


رمز PHP:
<code style="white-space:nowrap"> <code> <?php

/*
* @author: Ahmed H AboElnasser <[email protected]>
* @license MIT
* @since: Class available since EgySolutions Framework 0.1 Beta
* @link: http://www.egysolutions.net
* Requires: PHP 5.1.4+
* @package: EgySolutions Framework
* @category: core
* @subpackage upload
*/
class upload
{
private
$file = array();
private
$upload_folder = '';
private
$max_filesize = 0; // in bytes!
private $valid_extensions = array();
private
$extension = '';
private
$new_filename = '';

public
$filename = '';
public
$done = false;


/**
* Create an upload stream, check filesize and extension as well as correct upload form
*



* @global $cfg
*/
function __construct( $file = array(), $upload_folder = '', $new_filename = '', $valid_extensions = array(), $max_filesize = 0 )
{
global
$cfg;

// Set class vars
$this->file = $file;
$this->filename = $this->file&#91;'name'&#93;;
$this->valid_extensions = $valid_extensions;
$this->new_filename = $new_filename;
$this->upload_folder = $upload_folder;

// check if the array is filled
if( !isset( $this->file&#91;'name'&#93; ) OR !isset( $this->file&#91;'tmp_name'&#93; ) OR !isset( $this->file&#91;'size'&#93; ) )
return
false;

// max filesize in bytes
$this->max_filesize = ( $max_filesize != 0 ) ? $max_filesize : $cfg->max_upload_filesize;

if(
$this->_check_extension() AND $this->_check_filesize() )
{
$this->filename = $this->new_filename . '.' . $this->extension;
$this->done = move_uploaded_file($this->file&#91;'tmp_name'&#93;, $this->upload_folder . $this->filename );
}
else
{
return
false;
}
}

/**
* Check if the exitension is valid
*/
private function _check_extension()
{
$info = explode('.',$this->filename);;
$ext = $info&#91;(count($info))-1&#93;;

if(
in_array( $ext, $this->valid_extensions ) )
{
$this->extension = strtolower($ext);
return
true;
}
else
return
false;
}

/**
* Check if the filesize is valid
*/
private function _check_filesize()
{
if(
$this->file&#91;'size'&#93; < $this->max_filesize )
return
true;
else
return
false;
}
}
?>
</code> </code>










©المشاركات المنشورة تعبر عن وجهة نظر صاحبها فقط، ولا تُعبّر بأي شكل من الأشكال عن وجهة نظر إدارة المنتدى©