<?php
/************************************
/
/ @ script : My Easy Copy
/ @ version : 1.3 beta
/ @ date created : 31-8-2006
/ @ created : naif php
/ @ site : www.naifphp.net
/
************************************/
class MyEasyCopy {
var $Url;
var $Path = "./";// don't add the => '/' in end when add folder name.Ex("./folder_copy");
var $CopyName;
var $errors = array(
" Please Enter The File Link !",
" The file wasn't found ! ",
" Can't Read The File !",
" File was created successfuly , file size : ",
" File wasn't created, please try again ! ");
// Main abstract method to handle all mattres
function EasyCopy()
{
$this->Url = strip_tags($_GET['Url']);
$new_name = (empty($this->CopyName)) ? md5(date("h_i_s")) : $this->CopyName;
if (isset($_GET['get']) && $_GET['get'] == "Copy")
{
if (empty($this->Url))
{
return $this->errors[0];
}
else
{
if(file_exists($this->Path) == false)
{
return $this->errors[1];
}
else
{
@set_time_limit(0);
$old_name = str_replace('/','',strrchr($this->Url,'/'));
$str = $this->GetStretchFile($old_name);
$diff = @fopen($this->Url,'rb');
if(!$diff)
{
return $this->errors[2];
}
else
{
$startmtime = microtime();
$con = '';
$new_co = @fopen($this->Path .'/'.$new_name.$str,'w');
while(!feof($diff))
{
$con .= @fread($diff,1024);
}
$created = @fwrite($new_co,$con);
@fclose($new_co);
@fclose($diff);
$endmtime = microtime();
$i = strrpos($startmtime," ");
$startmtime = substr($startmtime,$i+1,strlen($startmtime)-$i)+substr($startmtime,0,$i);
$i = strrpos($endmtime," ");
$endmtime = substr($endmtime,$i+1,strlen($endmtime)-$i)+substr($endmtime,0,$i);
$totaltime = $endmtime - $startmtime;
$kbs = round((strlen($con)/1024)/$totaltime);
$port = ("Fast Translate File : ".number_format($kbs)." kb/s , Time Used : $totaltime Second <br>\n");
if($created)
{
return $this->errors[3] . $this->GetSize($new_name.$str) .'<br>'. $port;
}
else
{
return $this->errors[4];
}
}
}
}
}
}
// Interface
function GetInfo ()
{
$form = "<FORM METHOD='GET'>";
$form .= "File Url : ";
$form .= "<INPUT TYPE='TEXT' NAME='Url'>";
$form .= "<INPUT TYPE='HIDDEN' NAME='get' VALUE='Copy'>";
$form .= "<INPUT TYPE='SUBMIT' VALUE='Get Copiedy'>";
$form .= "</FORM><HR>";
return $form;
}
// Getting the extension of the file
function GetStretchFile($name)
{
$GetStretch = @explode('.',$name);
$reStretch = @count($GetStretch) - 1;
$Stretch = '.'.$GetStretch[$reStretch];
return $Stretch;
}
// handling size, return full size option : 500 Kb
function GetSize($file_name)
{
$filesize = filesize($this->Path .'/'. $file_name);
if ($filesize >= 1073741824)
{
$filesize = number_format($filesize / 1073741824, 1) . ' Gb';
}
else if ($filesize >= 1048576)
{
$filesize = number_format($filesize / 1048576, 1) . ' Mb';
}
else if ($filesize >= 1024)
{
$filesize = number_format($filesize / 1024, 1) . ' Kb';
}
else
{
$filesize = number_format($filesize, 1) . ' b';
}
return $filesize;
}
} // End Class :)
?>