вопрос
Пользуюсь модулем; тык
Решил сделать красивое название фото: место 1406986118_676266.jpg сделал 1406986118.jpg
в файле нашел engine/ajax/xfields.upload.php (с:256)
и изменил на
Фото повторяется дважды при загрузке больше 3-4 фото, я знаю, что проблема при генерации названия фото(1406986118) Подскажите пожалуйста, как исправить эту проблему? Заранее спасибо!
Решил сделать красивое название фото: место 1406986118_676266.jpg сделал 1406986118.jpg
в файле нашел engine/ajax/xfields.upload.php (с:256)
$dd['name_real'] = $dd['name'];
$dd['name'] = $file_prefix .'_'.$dd['name'];
$dd['file_real'] = $dd['path']['ftp'] .$dd['name'];
и изменил на
$dd['name_real'] = $dd['name'];
$dd['name'] = explode( ".", $dd['name'] );
$dd['name'] = end( $dd['name'] );
$dd['name'] = $file_prefix . "." . $dd['name'];
$dd['file_real'] = $dd['path']['ftp'] . $dd['name'];
/*
$dd['name_real'] = $dd['name'];
$dd['name'] = $file_prefix . '_' . $dd['name'];
$dd['file_real'] = $dd['path']['ftp'] . $dd['name'];
*/
Фото повторяется дважды при загрузке больше 3-4 фото, я знаю, что проблема при генерации названия фото(1406986118) Подскажите пожалуйста, как исправить эту проблему? Заранее спасибо!
<?php
if(isset($_REQUEST['isnull'])) exit;
@error_reporting( E_ALL ^E_NOTICE );
@ini_set( 'display_errors',true );
@ini_set( 'html_errors',false );
@ini_set( 'error_reporting',E_ALL ^E_NOTICE );
define( 'DATALIFEENGINE',true );
define( 'ROOT_DIR','../..');
define( 'ENGINE_DIR','..');
if (@ini_get( 'safe_mode') == 1)
define( 'FOLDER_PREFIX',"");
else
define( 'FOLDER_PREFIX',date( "Y-m",time() ) );
require_once ENGINE_DIR .'/data/config.php';
if( $config['http_home_url'] == "") {
$config['http_home_url'] = explode( "engine/ajax/xfields.upload.php",$_SERVER['PHP_SELF'] );
$config['http_home_url'] = reset( $config['http_home_url'] );
$config['http_home_url'] = "http://".$_SERVER['HTTP_HOST'] .$config['http_home_url'];
}
require_once ENGINE_DIR .'/classes/mysql.php';
require_once ENGINE_DIR .'/data/dbconfig.php';
require_once ENGINE_DIR .'/modules/functions.php';
if(function_exists('dle_session'))
dle_session();
else
session_start();
require_once ROOT_DIR .'/language/'.$config['langs'] .'/adminpanel.lng';
$config['charset'] = ($lang['charset'] != '') ?$lang['charset'] : $config['charset'];
@header( "Content-type: text/html; charset=".$config['charset'] );
$user_group = get_vars( "usergroup");
if( !$user_group ) {
$user_group = array ();
$db->query( "SELECT * FROM ".USERPREFIX ."_usergroups ORDER BY id ASC");
while ( $row = $db->get_row() ) {
$user_group[$row['id']] = array ();
foreach ( $row as $key =>$value ) {
$user_group[$row['id']][$key] = $value;
}
}
set_vars( "usergroup",$user_group );
$db->free();
}
function AJAXMessage($t) {
global $lang;
return '<span class="error">'.$t.'</span>';
}
$result_type = intval($_REQUEST['type']);
$result_type = 1;
$result_isurl = intval($_REQUEST['x']);
$result_isadm = intval($_REQUEST['a']);
$result_news_id = intval($_REQUEST['newsid']);
$is_xfields_upload = false;
if ($result_type==1) {
require_once ENGINE_DIR .'/inc/xfields.upload.php';
$result_field = $_REQUEST['field'];
$result_option = false;
$xfields = xfieldsload();
foreach($xfields as $id =>$value) {
if (strtolower($value[0])==strtolower($result_field)) {
$result_option = xfield_get_option($value);
break;
}
}
if (is_array($result_option))
$is_xfields_upload = true;
}else
die(AJAXMessage("Hacking attempt!!!"));
if(count($_POST)<1)
die(AJAXMessage($lang['xfieldupload_err_8']));
if ($result_isurl==1 and !is_array($_FILES['userfile']))
$is_xfields_upload = false;
if ($result_isurl==2 and $_REQUEST['value']=='')
$is_xfields_upload = false;
if ($result_isurl==3 and $_REQUEST['value']=='')
$is_xfields_upload = false;
if (!$is_xfields_upload)
die(AJAXMessage($lang['xfieldupload_err_1']));
$is_logged = false;
$member_id = array ();
require_once ENGINE_DIR .'/modules/sitelogin.php';
if( !$is_logged )
$member_id['user_group'] = 5;
$image_field_apped = (isset($_SESSION['n0xfuploas'][$result_option['field']])?$_SESSION['n0xfuploas'][$result_option['field']]:0);
$image_field_multiple = ($result_option['multiple']!=''or $result_option['multiple_max']>0);
$result_author = ($result_news_id>0?$db->super_query( "SELECT autor FROM ".PREFIX ."_post where id = '{$result_news_id}' LIMIT 1"):false);
$result_author = ($result_author?$result_author['autor']:$member_id['name']);
if ($result_isurl==3) {
$result_error = ' '.$lang['xfieldupload_err_3'];
$result_value = xfields_get_hash($_REQUEST['value']);
$result_value = $db->safesql(trim(strip_tags($result_value)));
if($result_value=='')
die(AJAXMessage("Hacking attempt!"));
$result_path = xfieldsGetPath($result_option,$result_value);
if($result_option['result']=='file'and !$result_option['notag']) {
$result_value = intval($result_value);
$row = $db->super_query( "SELECT id, onserver FROM ".PREFIX ."_files where id = '{$result_value}' LIMIT 1");
if($row){
$db->query( "DELETE FROM ".PREFIX ."_files WHERE id='{$row['id']}'");
$result_error = '';
$result_field = '[attachment='.$result_value.']';
@unlink($result_path['ftp'].$row['onserver']);
}
}else
if(($result_option['notag'] and ($result_option['result']=='file') or $result_option['result']=='video'or $result_option['result']=='audio')){
$real_name = basename($result_value);
if($real_name!=''and @file_exists($result_path['ftp'].$real_name)){
if($result_path['bd']!==false) {
$row = $db->super_query( "SELECT id, onserver FROM ".PREFIX ."_files where news_id='{$result_news_id}' and onserver='{$result_path['bd']}{$real_name}' LIMIT 1");
if($row)
$db->query( "DELETE FROM ".PREFIX ."_files WHERE id='{$row['id']}'");
}
$result_error = '';
if($result_option['notag'])
$result_field = $result_value;
else
if($result_option['result']=='video')
$result_field = '[video='.$result_value.']';
else
if($result_option['result']=='audio')
$result_field = '[audio='.$result_value.']';
@unlink($result_path['ftp'].$real_name);
}
}else
if($result_option['result']=='image') {
$real_name = basename($result_value);
if($real_name!=''and @file_exists($result_path['ftp'].$real_name)){
if($result_path['bd']!==false) {
if($result_news_id==0)
$row = $db->super_query( "SELECT id, images FROM ".PREFIX ."_images where news_id = '0' and author = '{$result_author}' LIMIT 1");
else
$row = $db->super_query( "SELECT id, images FROM ".PREFIX ."_images where news_id = '{$result_news_id}' LIMIT 1");
$listimages = (($row and $row['images']!="")?explode("|||",$row['images']):array());
foreach($listimages as $dd)
if(strcasecmp($dd,$result_path['bd'].$real_name)==0) {
unset($listimages[$id]);
$row['images'] = implode( "|||",$listimages );
if(trim($row['images']==''))
$db->query( "DELETE FROM ".PREFIX ."_images where id = '{$row['id']}'");
else
$db->query( "UPDATE ".PREFIX ."_images set images='{$row['images']}' where id = '{$row['id']}'");
break;
}
}
$result_error = '';
if($result_option['notag'])
$result_field = $result_value;
else
if(file_exists($result_path['ftp']."thumbs/".$real_name))
$result_field = '[thumb]'.$result_value.'[/thumb]';
else
$result_field = '[img]'.$result_value.'[/img]';
@unlink($result_path['ftp'].$real_name);
@unlink($result_path['ftp']."thumbs/".$real_name);
}
}
if($result_error=='') {
$image_field_apped--;
}else
die(AJAXMessage($result_error));
}else {
if ($result_option['result']=='image')
$allowed_extensions = array ("gif","jpg","png","jpe","jpeg");
else
if ($result_option['result']=='audio')
$allowed_extensions = array ("mp3");
else
if ($result_option['result']=='video')
$allowed_extensions = array ("avi","mp4","wmv","mpg","flv","m4v","m4a","mov","3gp","f4v");
else
if ($result_option['result']=='file') {
if (isset($user_group[$member_id['user_group']]['files_type']))
$config['files_type'] = $user_group[$member_id['user_group']]['files_type'];
if (isset($result_option['files_type']))
$config['files_type'] = $result_option['files_type'];
$allowed_extensions = explode(',',strtolower($config['files_type']));
}else
$allowed_extensions = array();
$uploadFiles = array();
if ($result_isurl==2) {
$fileurl = str_replace( "\\","/",$_REQUEST['value'] );
$uploadFiles[] = array(
'file'=>$fileurl,
'name'=>basename($fileurl),
'size'=>@filesize_url( $fileurl ),
'error'=>'',
);
}else
if ($result_isurl==1) {
if(is_array($_FILES['userfile']['tmp_name'])){
foreach($_FILES['userfile']['tmp_name'] as $ii =>$dd){
$uploadFiles[] = array(
'file'=>$_FILES['userfile']['tmp_name'][$ii],
'name'=>$_FILES['userfile']['name'][$ii],
'size'=>$_FILES['userfile']['size'][$ii],
'error'=>$_FILES['userfile']['error'][$ii],
);
}
}else {
$uploadFiles[] = array(
'file'=>$_FILES['userfile']['tmp_name'],
'name'=>$_FILES['userfile']['name'],
'size'=>$_FILES['userfile']['size'],
'error'=>$_FILES['userfile']['error'],
);
}
foreach($uploadFiles as &$dd){
if ( $dd['error'] !== UPLOAD_ERR_OK) {
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
$dd['error'] = 'PHP Error: The uploaded file exceeds the upload_max_filesize directive in php.ini';break;
case UPLOAD_ERR_FORM_SIZE:
$dd['error'] = 'PHP Error: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';break;
case UPLOAD_ERR_PARTIAL:
$dd['error'] = 'PHP Error: The uploaded file was only partially uploaded';break;
case UPLOAD_ERR_NO_FILE:
$dd['error'] = 'PHP Error: No file was uploaded';break;
case UPLOAD_ERR_NO_TMP_DIR:
$dd['error'] = 'PHP Error: Missing a PHP temporary folder';break;
case UPLOAD_ERR_CANT_WRITE:
$dd['error'] = 'PHP Error: Failed to write file to disk';break;
case UPLOAD_ERR_EXTENSION:
$dd['error'] = 'PHP Error: File upload stopped by extension';break;
default:
$dd['error'] = 'Unknown upload error';break;
}
}else
$dd['error'] = '';
}
}
if(($image_field_multiple and $image_field_apped>=$result_option['multiple_max']) or (!$image_field_multiple and $image_field_apped>1)) {
$result_error = ' '.$lang['xfieldupload_err_7'];
}else
if(($result_option['result']=='image'and !$user_group[$member_id['user_group']]['allow_image_upload']) or
($result_option['result']!='image'and (!$user_group[$member_id['user_group']]['allow_file_upload'] or $config['files_allow']!="yes"))
)
$result_error = ' '.$lang['xfieldupload_err_4'];
else
foreach($uploadFiles as &$dd){
$dd['name'] = totranslit($dd['name']);
$dd['type'] = pathinfo($dd['name']);
$dd['type'] = $dd['type']['extension'];
$zz = $image_field_apped+1;
if(($image_field_multiple and $zz>$result_option['multiple_max']) or (!$image_field_multiple and $zz>1)) {
$dd['error'] = $lang['xfieldupload_err_7'];
}else
if((stripos($dd['name'],".htaccess")!== false))
$dd['error'] = "Hacking attempt! 2";
else
if(!in_array(strtolower($dd['type']),$allowed_extensions))
$dd['error'] = ' '.$lang['xfieldupload_err_5']." \"".strtolower( $dd['type'] )."\" (".implode(', ',$allowed_extensions).")";
else
if($dd['size']>0 and $result_option['result']!='image'and intval($config['max_file_size']) and $dd['size']>($config['max_file_size']*1024))
$dd['error'] = ' '.$lang['files_too_big'];
else
if($dd['size']>0 and $result_option['result']=='image'and intval($config['max_up_size']) and $dd['size']>($config['max_up_size']*1024))
$dd['error'] = ' '.$lang['images_big'];
else {
$dd['path'] = xfieldsGetPath($result_option);
if (!is_array($dd['path'])) {
$dd['error'] = ' '.$dd['path'];
$dd['path'] = false;
}
}
if($dd['error']!='') continue;
$file_prefix = time() +rand( 1,100 );
$dd['name_real'] = $dd['name'];
$dd['name'] = $file_prefix .'_'.$dd['name'];
$dd['file_real'] = $dd['path']['ftp'] .$dd['name'];
if ($result_isurl==1)
@move_uploaded_file( $dd['file'],$dd['file_real'] );
else
if ($result_isurl==2)
@copy( $dd['file'],$dd['file_real'] );
if( @file_exists( $dd['file_real'] ) ) {
@chmod( $dd['file_real'] ,0666 );
$file_size = @filesize( $dd['file_real'] );
if($file_size!=$dd['size']) {
$dd['size'] = $file_size;
if($dd['size']>0 and $result_option['result']!='image'and intval($config['max_file_size']) and $dd['size']>($config['max_file_size']*1024)) {
$dd['error'] = ' '.$lang['files_too_big'];
}else
if($dd['size']>0 and $result_option['result']=='image'and intval($config['max_up_side']) and $dd['size']>($config['max_up_size']*1024)) {
$dd['error'] = ' '.$lang['images_big'];
}
}
}else
$dd['error'] = ' '.$lang['xfieldupload_err_6'];
if($dd['error']!='')
@unlink( $dd['file_real'] );
else
$image_field_apped++;
}
$added_time = time() +($config['date_adjust'] * 60);
$out_fields = array();
$out_fields_input = array();
if ($result_error!='')
$out_fields[] = AJAXMessage($result_error);
else
if ($result_option['result']=='image') {
$inserts = array();
foreach($uploadFiles as &$dd){
if($dd['error']==''and $dd['path']['bd']!==false)
$inserts[] = $dd['path']['bd'].$dd['name'];
}
if(count($inserts)>0) {
if($result_news_id==0)
$row = $db->super_query( "SELECT id, images FROM ".PREFIX ."_images where news_id = '0' and author = '$result_author' LIMIT 1");
else
$row = $db->super_query( "SELECT id, images FROM ".PREFIX ."_images where news_id = '$result_news_id' LIMIT 1");
if(!$row or intval($row['id'])<1) {
$inserts = implode( "|||",$inserts );
$db->query( "INSERT INTO ".PREFIX ."_images (images, author, news_id, date) values ('{$inserts}', '{$result_author}', '{$result_news_id}', '{$added_time}')");
}else {
$listimages = ($row['images']==""?array():explode("|||",$row['images']));
$inserts = array_diff_assoc($inserts,$listimages);
$listimages = array_merge($listimages,$inserts);
$row['images'] = implode( "|||",$listimages );
$db->query( "UPDATE ".PREFIX ."_images set images='{$row['images']}' where id = '{$row['id']}'");
}
}
include_once ENGINE_DIR .'/classes/thumb.class.php';
foreach ($uploadFiles as &$dd) {
if($dd['error']!=''){
$out_fields[] = AJAXMessage($dd['name'].': '.$dd['error']);
continue;
}
$image_url = $dd['path']['http'].$dd['name'];
$is_upload_ftp = ((stripos($dd['path']['ftp'],'ftp://'))!==false);
$result_option_size = (isset($result_option['size'])?$result_option['size']:false);
$image_url_thumb = '';
if (!$result_option['nothumb']) {
if (!$result_option_size) $result_option_size = $config['max_image'];
try {
$thumb = new thumbnail( $dd['file_real'] );
if( $thumb->size_auto( $result_option_size,$config['t_seite'] ) ) {
$thumb->jpeg_quality( $config['jpeg_quality'] );
if( $config['allow_watermark'] == "yes") $thumb->insert_watermark( $config['max_watermark'] );
if($is_upload_ftp){
$tmpfilename = tempnam(sys_get_temp_dir(),'xfu');
$thumb->save( $tmpfilename );
@unlink($dd['path']['ftp']."thumbs/".$dd['name']);
copy($tmpfilename,$dd['path']['ftp']."thumbs/".$dd['name']);
@unlink($tmpfilename);
}else{
$thumb->save( $dd['path']['ftp']."thumbs/".$dd['name'] );
}
@chmod( $dd['path']['ftp']."thumbs/".$dd['name'],0666 );
}
}catch (Exception $e) {}
if( @file_exists( $dd['path']['ftp']."thumbs/".$dd['name'] ) )
$image_url_thumb = $dd['path']['http']."thumbs/".$dd['name'];
$result_option_size = $config['max_up_side'];
}else {
if (!$result_option_size) $result_option_size = $config['max_up_side'];
}
if( $config['allow_watermark'] == "yes"or $result_option['size'] ) {
try {
$thumb = new thumbnail( $dd['file_real'] );
$thumb->jpeg_quality( $config['jpeg_quality'] );
if( $result_option_size ) $thumb->size_auto( $result_option_size,$config['t_seite'] );
if( $config['allow_watermark'] == "yes") $thumb->insert_watermark( $config['max_watermark'] );
if($is_upload_ftp){
$tmpfilename = tempnam(sys_get_temp_dir(),'xfu');
$thumb->save( $tmpfilename );
@unlink($dd['file_real']);
copy($tmpfilename,$dd['file_real']);
@unlink($tmpfilename);
}else{
$thumb->save( $dd['file_real'] );
}
}catch (Exception $e) {}
}
if ($result_option['notag']) {
if ($image_url_thumb!='')
$out_field = $image_url_thumb;
else
$out_field = $image_url;
}else {
if ($image_url_thumb!='')
$out_field = "[thumb]".$image_url."[/thumb]";
else
$out_field = "[img]".$image_url."[/img]";
}
$out_fields_input[] = $out_field;
$out_field = xfields_get_exists($result_option,$out_field);
$out_field = (is_array($out_field)?$out_field:array($out_field));
$out_fields = array_merge($out_fields,$out_field);
}
}else
foreach($uploadFiles as &$dd) {
if($dd['error']!='') {
$out_fields[] = AJAXMessage($dd['name'].': '.$dd['error']);
continue;
}
if($dd['path']['bd']!==false){
$db->query( "INSERT INTO ".PREFIX ."_files (news_id, name, onserver, author, date) values ('{$result_news_id}', '{$dd['name_real']}', '{$dd['path']['bd']}{$dd['name']}', '{$result_author}', '{$added_time}')");
$insert_id = $db->insert_id();
}else
$insert_id = '0';
$image_url = $dd['path']['http'].$dd['name'];
if ($result_option['result']=='audio') {
if ($result_option['notag'])
$out_field = $image_url;
else
$out_field = "[audio={$image_url}]";
}else
if ($result_option['result']=='video') {
if ($result_option['notag'])
$out_field = $image_url;
else
$out_field = "[video={$image_url}]";
}else
if ($result_option['result']=='file') {
if ($result_option['notag'])
$out_field = $image_url;
else
$out_field = "[attachment=".$insert_id ."]";
}
$out_fields_input[] = $out_field;
$out_field = xfields_get_exists($result_option,$out_field);
$out_field = (is_array($out_field)?$out_field:array($out_field));
$out_fields = array_merge($out_fields,$out_field);
}
if (count($out_fields)<1)
die(AJAXMessage('Internal error'));
$result_html = (is_array($out_fields)?implode('',$out_fields):$out_fields);
$result_field = (is_array($out_fields_input)?implode(($image_field_multiple?$result_option['multiple']:''),$out_fields_input):$out_fields_input);
}
function json_strip($s){
$s = str_replace('"','\"',$s );
$s = str_replace(array("{","}","\r","\n","\t"),'',$s );
return $s;
}
$_SESSION['n0xfuploas'][$result_option['field']] = $image_field_apped;
$image_allowed_upload = !(($image_field_multiple and $image_field_apped>=$result_option['multiple_max']) or (!$image_field_multiple and $image_field_apped>1));
$result_html = '{"content":"'.json_strip($result_html).'","allowed_upload":"'.($image_allowed_upload?'1':'0').'","field_value":"'.json_strip($result_field).'","filed_delimiter":"'.json_strip($result_option['multiple']).'"}';
$db->close();
$result_html = str_ireplace(array('%7BTHEME%7D','{THEME}'),$config['http_home_url'].'templates/'.$config['skin'],$result_html);
die($result_html);