sibtracker/system/modules/torrent/upload.php
2019-05-18 13:46:03 +08:00

65 lines
2.8 KiB
PHP

<?
if( ! defined( 'DATALIFEENGINE' ) ) {die( "Hacking attempt!" );}
if (@ini_get( 'safe_mode' ) == 1)define( 'FOLDER_PREFIX', "" ); else define( 'FOLDER_PREFIX', date( "Y-m" ) );
$idpost = $row['id'];
$file_prefix = time() + rand( 1, 100 );
$file_prefix .= "_";
$file_prefix = FOLDER_PREFIX.'/'.$file_prefix;
$current_image = 'tor_add';
$image = $_FILES[$current_image]['tmp_name'];
$image_name = $_FILES[$current_image]['name'];
$image_size = $_FILES[$current_image]['size'];
$error_code = $_FILES[$current_image]['error'];
$img_name_arr = explode( ".", $image_name );
$type = totranslit( end( $img_name_arr ) );
if( $image_name != "" ) {
$curr_key = key( $img_name_arr );
unset( $img_name_arr[$curr_key] );
$image_name = totranslit( implode( ".", $img_name_arr ) ) . "." . $type;
}
if(substr($image_name, -8) == ".torrent") {
if( ! is_dir( ROOT_DIR . "/uploads/torrents/" . FOLDER_PREFIX ) ){
mkdir( ROOT_DIR . "/uploads/torrents/" . FOLDER_PREFIX, 0777 );
chmod( ROOT_DIR . "/uploads/torrents/" . FOLDER_PREFIX, 0777 );
}
@move_uploaded_file( $image, ROOT_DIR . "/uploads/torrents/" . $file_prefix . $image_name );
if( @file_exists( ROOT_DIR . "/uploads/torrents/" . $file_prefix . $image_name ) ) {
if( intval( $config['max_file_size'] ) and @filesize( ROOT_DIR . "/uploads/torrents/" . $file_prefix . $image_name ) > ($config['max_file_size'] * 1024) ) {
@unlink( ROOT_DIR . "/uploads/torrents/" . $file_prefix . $image_name );
} else {
@chmod( ROOT_DIR . "/uploads/torrents/" . $file_prefix . $image_name, 0666 );
//********* Tracker by MSW *** start *********//
require_once( ROOT_DIR."/system/classes/torrent.class.php" );
$tr_file = ROOT_DIR."/uploads/torrents/".$file_prefix.$image_name;
$torrent = new Torrent($tr_file);
if($error = $torrent->errors()){
}else{
$files_size = $torrent->size();
$hash = $torrent->hash_info();
$e_hash = addslashes(pack("H*", $hash));
$tr_fild = ", info_hash, size, ctime";
$tr_info = ", '{$e_hash}', '{$files_size}', '".time()."'";
//********* Tracker by MSW *** stop *********//
$db->query( "INSERT INTO " . PREFIX . "_torrents (news_id, name, onserver, author {$tr_fild}) values ('{$row['id']}', '$image_name', '{$file_prefix}{$image_name}', '{$member_id[name]}' {$tr_info})" );
$id_upfile = $db->insert_id();
$full_story .= "<br />[torrent=$id_upfile]";
$db->query( "UPDATE " . PREFIX . "_post SET full_story='$full_story' where id = '$idpost'" );
}
}
}
}
?>