Автор Тема: Проблем със php код на компонент за джумла?  (Прочетена 1385 пъти)

0 Потребители и 1 Гост преглежда(т) тази тема.

deiman

  • Newbie
  • *
  • Благодарности
  • -Казани: 0
  • -Получени: 0
  • Публикации: 14
Здравейте, първо компонентът е този цък, прецених че единствено той ми върши работа предвид това което искам да правя (хората да ъплоудват уроци, аз да ги одобрявам и качвам на външен сървър. Та, проблемът със този компонент е:

 Ето го и самият код

defined ( ' _VALID_MOS ' ) or die( ' Direct Access to this location is not allowed. ' );

# Variabili
define(  ' _base_A '  , $mosConfig_absolute_path .  ' /administrator/components/com_ftpsystem/ ' );
define(  ' _base_W '  , $mosConfig_absolute_path .  ' /components/com_ftpsystem/ ' );


require_once(_base_A .  " /config.ftpsystem.php " );
require_once(_base_A .  " /class.ftpsystem.php " );

$gallerypath = $mosConfig_live_site .  " /components/com_ftpsystem " ;

# Trova il file lingua se esistente
if (file_exists($mosConfig_absolute_path .  ' /components/com_ftpsystem/language/ '  . $mosConfig_lang .  ' .php ' )) {
include($mosConfig_absolute_path .  ' /components/com_ftpsystem/language/ '  . $mosConfig_lang .  ' .php ' );
} else {
include($mosConfig_absolute_path .  ' /components/com_ftpsystem/language/english.php ' );
}
# definisci i permessi
$is_editor = (strtolower($my->usertype) ==  ' editor '  || strtolower($my->usertype) ==  ' administrator '  || strtolower($my->usertype) ==  ' super administrator ' );
$is_user = (strtolower($my->usertype) <>  '  ' );

$uid = intval(mosGetParam($_REQUEST,  " uid " , 0));


if ($my->id==0)
mosRedirect(sefRelToAbs( " index.php?option=com_user&view=login&Itemid=$Itemid " ,   '  ' ));

//////////////////////////////////////////////////
#to avoid RG emulation off problems
//////////////////////////////////////////////////
$id = mosGetParam($_REQUEST, " id " ,  '  ' );
$catid = mosGetParam($_REQUEST, " catid " ,  '  ' );
$func = mosGetParam($_REQUEST, " func " , '  ' );
$Itemid = mosGetParam($_REQUEST, " Itemid " , '  ' );
//////////////////////////////////////////////////

switch (@$func)
{
case  ' ftpupload ' : //add;
ftpupload_edit(0);
$event =  "  ' js_fnadd(); '  "  ;
echo  " " ;
break;

case  ' edit ' :
ftpupload_edit($id);
$event =  "  ' js_fnedit(); '  "  ;
echo  " " ;
break;

case  ' delete ' :
ftpupload_delete($id);
break;

case  ' save ' :
insertftpsystem($id);
break;

case  ' download ' :
$file = mosGetParam($_REQUEST, " file " , '  ' );
download($file);
break;

case  ' ftpuploadlist ' :
ftpuploadlist();
break;

case  ' help ' :
showhelptext();
break;

//default:
//ftpuploadlist();
//break;
}
 
function insertftpsystem($id)
{
global $database;

//$hidIsFilePath1 = 0;
$hidIsFilePath = $_REQUEST[ ' hidIsFilePath ' ];
/* if ( $id !=  '  '  && $id !=0)
{
if ($hidIsFilePath ==0)
 $hidIsFilePath1 = 1; // in edit already have file path
} */

$name         = $_REQUEST[ ' name ' ];
$description = $_REQUEST[ ' description ' ];

// get current userid & username from user table.
$user =& JFactory::getUser();
$userid = $user->get( ' id ' );
$username = $user->get( ' username ' );

$sFileDir = $mosConfig_absolute_path . ' uploads/ ' .$username ;//$mosConfig_absolute_path

if ($hidIsFilePath == 0)
{
$sFilename =  $_FILES[ " upfile1 " ][ " name " ];
$sFileType =  $_FILES[ " upfile1 " ][ " type " ];
$sFileSize  =  $_FILES[ " upfile1 " ][ " size " ];
$sFileTempPath  =  $_FILES[ " upfile1 " ][ " tmp_name " ];

recursive_mkdir($sFileDir);
$sFilePath = $sFileDir . ' / ' .$sFilename;

if ($sFileTempPath)
{
$result = copy ($sFileTempPath, $sFilePath );
//$result1  = move_uploaded_file($sFileTempPath,$sFilePath );
}
$path = $username . ' / ' . $sFilename ;

$updateFileQry =  " ,filepath= '  "  . $path .  "  ' ,  " .
   "  size= '  "  . $sFileSize .  "  '  " ;
}
else
{
$updateFileQry= '  ' ;
}
// echo $id;
if ($id ==  '  '  || $id == 0 )
{
$sql =  " INSERT INTO #__upload  "  .
   " (name,description,filepath,size,modifieddate,userid,published,ordering) "  .
   "  VALUES ( '  "  . $name .  "  ' , '  "  . $description .  "  ' , '  "  . $path .  "  ' , '  "  . $sFileSize .  "  ' ,NOW(), '  " . $userid. "  ' , ' 1 ' , ' 1 ' ) " ;
}
else
{
$sql =  " UPDATE #__upload  "  .
   "  SET name= '  "  . $name .  "  ' ,description= '  "  . $description .  "  '   " .$updateFileQry. "  ,modifieddate=NOW(),userid= '  " . $userid. "  '  WHERE id= "  . $id;
}
//echo $sql;
$database->setQuery($sql);
$database->query();
mosRedirect(sefRelToAbs( " index.php?option=com_ftpsystem&Itemid=$Itemid " ,   '  ' ));

}

function recursive_mkdir( $folder )
{
$folder = preg_split(  " /[\\\\\\\\\\/]/ "  , $folder );

$mkfolder =  '  ' ;
for(  $i=0 ; isset( $folder[$i] ) ; $i++ )
{
if(!strlen(trim($folder[$i])))continue;
$mkfolder .= $folder[$i];
if( !is_dir( $mkfolder ) ){
mkdir(  " $mkfolder "  ,  0777);
}
$mkfolder .= DIRECTORY_SEPARATOR;
}
}

function download($file)
{
$filepath =  ' uploads/ ' .$file;
if(file_exists($filepath))
{
set_time_limit(0);
output_file($filepath,$filepath,  ' text/plain ' );
}
else
{
echo  ' File not exists. ' ;
}
}

function ftpupload_delete($id)
{
global $database;
$sql =  " DELETE FROM #__upload WHERE id=$id " ;
$database->setQuery($sql);
$database->query();
mosRedirect(sefRelToAbs( " index.php?option=com_ftpsystem&Itemid=$Itemid " ,   '  ' ));
}
?>

////Super Administrator
function ftpuploadlist()
{
global $database;
?>
 


   
 
     
       
     
     
       
     
   
Сподели урок
"  id= "  " a> |  " >Upload |  "  class= " atext "  >Уславия за качване



             
               
               
               
               
               
             
 
               
 // get current userid & username from user table.
$cur_user =& JFactory::getUser();
$current_userid = $cur_user->get( ' id ' );
$current_username = $cur_user->get( ' username ' );
$current_usertype = $cur_user->usertype;//Super Administrator
//-- end Current User Getting


  // get type (upload user type ) from fileuploadtype table
$database->setQuery(  " SELECT type FROM #__fileuploadtype "  );
$sType = $database->loadResult();

$query1 =  "  SELECT fu.id, fu.name, fu.description, DATE_FORMAT(fu.modifieddate, ' %d-%m-%Y '  ) as modDate,  "  .
  "  fu.filepath, fu.size,u.id as userid,u.username,u.usertype  " .
  "  FROM #__upload fu   "  .
  "  LEFT JOIN #__users u ON u.id = fu.userid WHERE published= ' 1 '   " ;
if ($sType == 1 )//&& $current_usertype !=  ' Super Administrator '  )
$query1 = $query1.  "  AND fu.userid =  '  " .$current_userid . "  '  " ;

$database->setQuery($query1);
$rows = $database->Query();
$num_rows = mysql_num_rows($rows) ;
$k = 0;

if ($num_rows) {
for ($row_count = 0; $row_count < $num_rows; $row_count++)
{
$k = 1 - $k;
$id = mysql_result($rows,$row_count, ' id ' );
$name = mysql_result($rows,$row_count, ' name ' );
$description = mysql_result($rows,$row_count, ' description ' );
$date = mysql_result($rows,$row_count, ' modDate ' );
$size = mysql_result($rows,$row_count, ' size ' );
$filepath = mysql_result($rows,$row_count, ' filepath ' );
$uploaded_username = mysql_result($rows,$row_count, ' username ' );
$uploaded_usertype = mysql_result($rows,$row_count, ' usertype ' );
$uploaded_userid = mysql_result($rows,$row_count, ' userid ' );

$IsEdit = 0;
if ($sType == 2)
{
if ( $uploaded_userid == $current_userid || $current_usertype ==  ' Super Administrator '  )
{
$IsEdit = 1;
}
}
else
{
$IsEdit = 1;
}
if($row_count >0){
?>


  " >






 
              }

  }
  else
  {
  echo  ' ' ;
  }
?>
         
ИмеОписаниеДатаРазмер 

" >



" > 

' ;} " >
Geen bestanden gevonden

}
?>

function ftpupload_edit($uploadid)
{
global $database;

// echo $uploadid;
$hidIsFilePath = 0;
if ($uploadid != '  '  && $uploadid != 0)
{
$query1 =  " SELECT * FROM #__upload WHERE id= " .$uploadid;
//echo $query1;
$database->setQuery($query1);
//$rows   = $database->loadObjectList();
$rows = $database->Query();
$row_count=0;
$num_rows = mysql_num_rows($rows) ;

$name =  '  ' ;
$description =  '  ' ;
$filepath =  '  ' ;

if ($num_rows)
{
$id = mysql_result($rows,$row_count, ' id ' );
$name = mysql_result($rows,$row_count, ' name ' );
$description = mysql_result($rows,$row_count, ' description ' );
$filepath = mysql_result($rows,$row_count, ' filepath ' );
}
$hidIsFilePath =1;
}
?>

"  enctype= " multipart/form-data "  method= " post " >


   
 
     
       
     
     
       
     
 
FTP System
"  id= "  "  |  " >Качи урок |  "  class= " atext "  >Условия за качване


         
           
         
       

             
               
               
             
             
               
               
             
             
               
               
             
               
               
             
             
               
               
           
Име на урока : "  style= " width:250px "  />
Описание на урока :
Файл (за предпочитане не-конвертиран) :
                               

                   
                     

                     
               
"  # " ;
                   
" />
                 




}

function fsize_unit_convert($bytes)
{
$units = array( ' b ' ,  ' kb ' ,  ' mb ' ,  ' gb ' );
$converted = $bytes .  '   '  . $units[0];
for ($i = 0; $i < count($units); $i++)
{
if (($bytes/pow(1024, $i)) >= 1)
{$converted = round($bytes/pow(1024, $i), 2) .  '   '  . $units[$i];}
}
return $converted;
}

function output_file($file, $name, $mime_type= '  ' )
{
/*
This function takes a path to a file to output ($file),
the filename that the browser will see ($name) and
the MIME type of the file ($mime_type, optional).

If you want to do something on download abort/finish,
register_shutdown_function( ' function_name ' );
*/
if(!is_readable($file)) die( ' File not found or inaccessible! ' );

$size = filesize($file);
$name = rawurldecode($name);

/* Figure out the MIME type (if not specified) */
$known_mime_types=array(
" pdf "  =>  " application/pdf " ,
" txt "  =>  " text/plain " ,
" html "  =>  " text/html " ,
" htm "  =>  " text/html " ,
" exe "  =>  " application/octet-stream " ,
" zip "  =>  " application/zip " ,
" doc "  =>  " application/msword " ,
" xls "  =>  " application/vnd.ms-excel " ,
" ppt "  =>  " application/vnd.ms-powerpoint " ,
" gif "  =>  " image/gif " ,
" png "  =>  " image/png " ,
" jpeg " =>  " image/jpg " ,
" jpg "  =>   " image/jpg " ,
" php "  =>  " text/plain "
);

if($mime_type== '  ' ){
$file_extension = strtolower(substr(strrchr($file, " . " ),1));
if(array_key_exists($file_extension, $known_mime_types)){
$mime_type=$known_mime_types[$file_extension];
} else {
$mime_type= " application/force-download " ;
};
};

@ob_end_clean(); //turn off output buffering to decrease cpu usage

// required for IE, otherwise Content-Disposition may be ignored
if(ini_get( ' zlib.output_compression ' ))
ini_set( ' zlib.output_compression ' ,  ' Off ' );

header( ' Content-Type:  '  . $mime_type);
header( ' Content-Disposition: attachment; filename= "  ' .$name. '  "  ' );
header( " Content-Transfer-Encoding: binary " );
header( ' Accept-Ranges: bytes ' );

/* The three lines below basically make the
download non-cacheable */
header( " Cache-control: private " );
header( ' Pragma: private ' );
header( " Expires: Mon, 26 Jul 1997 05:00:00 GMT " );

// multipart-download and download resuming support
if(isset($_SERVER[ ' HTTP_RANGE ' ]))
{
list($a, $range) = explode( " = " ,$_SERVER[ ' HTTP_RANGE ' ],2);
list($range) = explode( " , " ,$range,2);
list($range, $range_end) = explode( " - " , $range);
$range=intval($range);
if(!$range_end) {
$range_end=$size-1;
} else {
$range_end=intval($range_end);
}

$new_length = $range_end-$range+1;
header( " HTTP/1.1 206 Partial Content " );
header( " Content-Length: $new_length " );
header( " Content-Range: bytes $range-$range_end/$size " );
} else {
$new_length=$size;
header( " Content-Length:  " .$size);
}

/* output the file itself */
$chunksize = 1*(1024*1024); //you may want to change this
$bytes_send = 0;
if ($file = fopen($file,  ' r ' ))
{
if(isset($_SERVER[ ' HTTP_RANGE ' ]))
fseek($file, $range);

while(!feof($file) &&
(!connection_aborted()) &&
($bytes_send<$new_length)
)
{
$buffer = fread($file, $chunksize);
print($buffer); //echo($buffer); // is also possible
flush();
$bytes_send += strlen($buffer);
}
fclose($file);
} else die( ' Error - can not open file. ' );

die();
}
?>
function showhelptext()
{
global $database;

$database->setQuery(  " SELECT type,helptext FROM #__fileuploadtype "  );
$rows = $database->Query();

$row_count=0;
$num_rows = mysql_num_rows($rows) ;

if ($num_rows)
{
$type = mysql_result($rows,$row_count, ' type ' );
$helptext = mysql_result($rows,$row_count, ' helptext ' );
}
  ?>
 

   
 
     
       
     
     
       
     
 
Качи урок
"  id= "  " /a> " >Качи урок | Условия за качване


         
           
         
       

             
               
             
             
               
             
           
 

 



}
?>

2.Ето линк към самият компонент да видите по подробно цък .Проблемът е че когато се качи файл, не излиза никакво съобщение за успешно качване. Най-добре ще е да стане като на тази ajax контактна форма, тоест при изпращане на писмо едно кръгче се върти долу, и при успешно изпращане се получава съобщение. Много добре ще е да го направя същото и на този компонент. Ето я и въпросната контакт форма цък Скролнете малко по надолу е.

Благодаря!