السلام عليكم ورحمة الله وبركاتة
كود PHP:
<?php
class upload
{
var $up ;
var $error ;
var $ext;
function upload($code,$exts,$maxs,$path,$truepath,$thumb,$twidth,$theight) {
/* Constants */
$sec_path=substr($path,3);
/* Constants */
/* Config */
$vexts=explode('-',$exts) ;
$msize= ($maxs*1024)*1024 ;
$new_w=$twidth ;
$new_h=$theight ;
$dngr= array('text/html','text/plain','application/xhtml+xml','application/x-php','text/php',
'application/x-httpd-php','application/x-javascript');
/* Config */
/* attributes */
$file_name=str_replace(" ","-",$_FILES['fileup']['name']);
$filetype=$_FILES['fileup']['type'];
$filesize=$_FILES['fileup']['size'];
$error =$_FILES['fileup']['error'];
$this->error = $error;
$fileext=strtolower(strrchr($file_name,'.')) ;
$this->ext = $fileext;
/* attributes */
/* generate new files names */
$filename=$code.$fileext;
$fpath=$path.$filename;
if($thumb == "T" ) {
$thname="thmb_".$code.$fileext;
$tpath=$path."thumb/".$thname;
}
/* generate new files names */
if (!in_array($fileext,$vexts)){ $main .= "<br> <br> هذا الامتداد غير مسموح به ".$refresh; }
elseif (in_array($filetype,$dngr)){ $main .= "<br> <br> هذا الملف خطر ".$refresh; }
elseif ($filesize > $msize){ $main .= "<br> <br> الحجم اكبر من المسموح به ".$refresh; }
else
{
if(move_uploaded_file($_FILES['fileup']['tmp_name'],$fpath))
{
$this->up = "T";
}
else
{
$this->up = "F";
}
}
}
}
?>
طريقة استخدامة :
كود PHP:
###- Random code for name -###
$rand =new random("n",6);
$code= $rand->salt;
###- Random code for name -###
/* Config upload */
$thumb= "F";
$twidth= "100";
$theight="100" ;
/* Config Upload */
/* Uploading */
$Upload = new upload($code,$exts,$maxs,$path,$truepath,$thumb,$twidth,$theight);
$okup = $Upload->up;
$error= $Upload->error;
$ext= $Upload->ext;
$photo=$code.$ext;
/* Uploading */
اريد اضافة تصغير الصورة تلقائيا عند الرفع الى 150 * 150
واكون شاكر لكم ..
تحياتى لكم .. عمرو محمد.