sibtracker/system/inc/newsimg/doaddimg.php
2019-05-18 13:46:03 +08:00

72 lines
3.8 KiB
PHP

<?php
if( ! defined( 'DATALIFEENGINE' ) ) {
die( "Hacking attempt!" );
}
$thumb_size = $config['poster_width'];
$thumb_size = explode ("x", $thumb_size);
if ( count($thumb_size) == 2) {$thumb_size = intval($thumb_size[0]) . "x" . intval($thumb_size[1]);
} else {$thumb_size = intval( $thumb_size[0] );}
$config['poster_width'] = $thumb_size;
$images_number = intval($_POST['images_number']);
for($image_i = 1; $image_i < ($images_number + 1); $image_i ++) {
$file_prefix = time() + rand( 1, 100 );
$file_prefix .= "_";
$image_name = "";
$type = "";
$current_image = 'addimg_' . $image_i;
$image = $_FILES[$current_image]['tmp_name'];
$image_name = $_FILES[$current_image]['name'];
$image_size = $_FILES[$current_image]['size'];
$error_code = $_FILES[$current_image]['error'];
if ($error_code !== UPLOAD_ERR_OK) {
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
$error_code = 'PHP Error: The uploaded file exceeds the upload_max_filesize directive in php.ini'; break;
case UPLOAD_ERR_FORM_SIZE:
$error_code = 'PHP Error: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; break;
case UPLOAD_ERR_PARTIAL:
$error_code = 'PHP Error: The uploaded file was only partially uploaded'; break;
case UPLOAD_ERR_NO_FILE:
$error_code = 'PHP Error: No file was uploaded'; break;
case UPLOAD_ERR_NO_TMP_DIR:
$error_code = 'PHP Error: Missing a PHP temporary folder'; break;
case UPLOAD_ERR_CANT_WRITE:
$error_code = 'PHP Error: Failed to write file to disk'; break;
case UPLOAD_ERR_EXTENSION:
$error_code = 'PHP Error: File upload stopped by extension'; break;
default:
$error_code = 'Unknown upload error'; break;
} }
$img_name_arr = explode( ".", $image_name );
$type = totranslit( end( $img_name_arr ) );
if( strpos ( $type, "php" ) !== false ) die("Hacking attempt!");
if( $image_name != "" ) {
$curr_key = key( $img_name_arr );
unset( $img_name_arr[$curr_key] );
$image_name = totranslit( implode( ".", $img_name_arr ) ) . "." . $type;
}
@move_uploaded_file( $image, ROOT_DIR . "/uploads/covers/" . $file_prefix . $image_name );
if( @file_exists( ROOT_DIR . "/uploads/covers/" . $file_prefix . $image_name ) ) {
@chmod( ROOT_DIR . "/uploads/covers/" . $file_prefix . $image_name, 0666 );
$url = '/covers/' . $file_prefix . $image_name;
include_once SYSTEM_DIR . '/classes/thumb.class.php';
$thumb = new thumbnail( ROOT_DIR . "/uploads/covers/" . $file_prefix . $image_name );
if( $thumb->size_auto( $config['poster_width'], 0 ) ) {
$thumb->jpeg_quality( $config['jpeg_quality'] );
if( $config['allow_watermark'] == "yes" ) $thumb->insert_watermark( $config['max_watermark'] );
$thumb->save( ROOT_DIR . "/uploads/covers/thumbs/" . $file_prefix . $image_name );
}
@chmod( ROOT_DIR . "/uploads/covers/thumbs/" . $file_prefix . $image_name, 0666 );
if( @file_exists( ROOT_DIR . "/uploads/covers/thumbs/" . $file_prefix . $image_name ) ) {
$th = '/covers/thumbs/' . $file_prefix . $image_name;
}
if( ($config['allow_watermark'] == "yes" ) or $config['max_up_side'] ) {
$thumb = new thumbnail( ROOT_DIR . "/uploads/covers/" . $file_prefix . $image_name );
$thumb->jpeg_quality( $config['jpeg_quality'] );
if( $config['max_up_side'] ) $thumb->size_auto( $config['max_up_side'] );
if( $config['allow_watermark'] == "yes" ) $thumb->insert_watermark( $config['max_watermark'] );
$thumb->save( ROOT_DIR . "/uploads/covers/" . $file_prefix . $image_name );
}}
if ($url != '') {$db->query("INSERT INTO ".PREFIX."_covers VALUES ('0', '$row', '$url', '$th')");}
}
?>