JavaScript 上传文件最大大小
Posted
技术标签:
【中文标题】JavaScript 上传文件最大大小【英文标题】:JavaScript upload file max size 【发布时间】:2014-02-19 18:21:13 【问题描述】:我必须上传代码 此代码用于 Datalife 引擎。如何使文件大小限制〜5Mb。以及将代码放在哪里?对不起,我英语不好。感谢您的帮助。
$allowed_extensions = array ("gif", "jpg", "png", "jpe", "jpeg" );
if ((isset($_FILES['post_add']) && $_FILES['post_add']!=''))
$file_prefix = time() + rand( 1, 100 );
$file_prefix .= "_";
define( 'FOLDER_PREFIX', date( "Y-m" ) );
if( ! is_dir( ROOT_DIR . "/uploads/posts/" . FOLDER_PREFIX ) )
@mkdir( ROOT_DIR . "/uploads/posts/" . FOLDER_PREFIX, 0777 );
@chmod( ROOT_DIR . "/uploads/posts/" . FOLDER_PREFIX, 0777 );
@mkdir( ROOT_DIR . "/uploads/posts/" . FOLDER_PREFIX . "/thumbs", 0777 );
@chmod( ROOT_DIR . "/uploads/posts/" . FOLDER_PREFIX . "/thumbs", 0777 );
$config_path_image_upload = ROOT_DIR . "/uploads/posts/" . FOLDER_PREFIX . "/";
$current_image = 'post_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 ( in_array( strtolower( $type ), $allowed_extensions) )
@move_uploaded_file( $image, $config_path_image_upload . $file_prefix . $image_name );
if( @file_exists( $config_path_image_upload . $file_prefix . $image_name ) )
@chmod( $config_path_image_upload . $file_prefix . $image_name, 0666 );
$row = $db->super_query( "SELECT COUNT(*) as count FROM " . PREFIX . "_images where author = '$member_id[name]' AND news_id = '$idpost'" );
if( ! $row['count'] )
$added_time = time() + ($config['date_adjust'] * 60);
$inserts = FOLDER_PREFIX . "/" . $file_prefix . $image_name;
$db->query( "INSERT INTO " . PREFIX . "_images (images, author, news_id, date) values ('$inserts', '$member_id[name]', '$idpost', '$added_time')" );
else
$row = $db->super_query( "SELECT images FROM " . PREFIX . "_images where author = '$member_id[name]' AND news_id = '$idpost'" );
if( $row['images'] == "" ) $listimages = array ();
else $listimages = explode( "|||", $row['images'] );
foreach ( $listimages as $dataimages )
if( $dataimages == FOLDER_PREFIX . "/" . $file_prefix . $image_name ) $error_image = "stop";
if( $error_image != "stop" )
$listimages[] = FOLDER_PREFIX . "/" . $file_prefix . $image_name;
$row['images'] = implode( "|||", $listimages );
$db->query( "UPDATE " . PREFIX . "_images set images='$row['images']' where author = '$member_id[name]' AND news_id = '$idpost'" );
include_once ENGINE_DIR . '/classes/thumb.class.php';
$tumb_ok = false;
$_POST['make_thumb'] = true;
$_POST['make_watermark'] = $config['allow_watermark'];
if( isset( $_POST['make_thumb'] ) )
$thumb = new thumbnail( $config_path_image_upload . $file_prefix . $image_name );
if( $thumb->size_auto( $config['max_image'], $_POST['t_seite'] ) )
$thumb->jpeg_quality( $config['jpeg_quality'] );
if( $config['allow_watermark'] == "yes" and $_POST['make_watermark'] == "yes" ) $thumb->insert_watermark( $config['max_watermark'] );
$thumb->save( $config_path_image_upload . "thumbs/" . $file_prefix . $image_name );
if( @file_exists( $config_path_image_upload . "thumbs/" . $file_prefix . $image_name ) ) $tumb_ok = true;
@chmod( $config_path_image_upload . "thumbs/" . $file_prefix . $image_name, 0666 );
$config['max_up_side'] = intval( $config['max_up_side'] );
if( ($config['allow_watermark'] == "yes" and $_POST['make_watermark'] == "yes") or $config['max_up_side'] )
$thumb = new thumbnail( $config_path_image_upload . $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" and $_POST['make_watermark'] == "yes" ) $thumb->insert_watermark( $config['max_watermark'] );
$thumb->save( $config_path_image_upload . $file_prefix . $image_name );
$short_story = preg_replace('/^<br \/>(.*?)(<br \/>)*?$/is', '$1', $short_story);
if ( $tumb_ok ) $short_story = "<!--TBegin--><a href=\"$config['http_home_url']uploads/posts/".FOLDER_PREFIX."/$file_prefix$image_name\" onclick=\"return hs.expand(this)\" ><img align=\"left\" src=\"$config['http_home_url']uploads/posts/".FOLDER_PREFIX."/thumbs/$file_prefix$image_name\" alt='$title' title='$title' /></a><!--TEnd-->".$short_story;
else $short_story = "<img src=\"$config['http_home_url']uploads/posts/".FOLDER_PREFIX."/$file_prefix$image_name\" align=\"left\" alt='$title' title='$title' />".$short_story;
$full_story = "<img src=\"$config['http_home_url']uploads/posts/".FOLDER_PREFIX."/$file_prefix$image_name\" align=\"center\" alt='$title' title='$title' />".$full_story;
$short_story = addslashes($short_story);
$full_story = addslashes($full_story);
$db->query( "UPDATE " . PREFIX . "_post SET short_story='$short_story', full_story='$full_story' where id = '$idpost'" );
我写信给谷歌翻译
【问题讨论】:
这与您的网络服务器设置有关,与 javascript 选项无关。 你的代码中错误抑制操作符的数量是荒谬的。 并且可以从javascript服务器设置中删除并制作javascript帮助? 【参考方案1】:为什么你想玩弄你的代码,而你可以在 admin cp 中设置它?该选项可以在文件和图像的系统设置中设置,新版本的 DLE 设置已移至用户组管理器
【讨论】:
以上是关于JavaScript 上传文件最大大小的主要内容,如果未能解决你的问题,请参考以下文章