Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript上载文件最大大小_Javascript_Upload_Filesize_Datalife Engine - Fatal编程技术网

JavaScript上载文件最大大小

JavaScript上载文件最大大小,javascript,upload,filesize,datalife-engine,Javascript,Upload,Filesize,Datalife Engine,我必须上传代码 此代码用于Datalife引擎。如何将文件大小限制为~5Mb。代码放在哪里?对不起,我英语说得不好。谢谢你的帮助 $allowed_extensions = array ("gif", "jpg", "png", "jpe", "jpeg" ); if ((isset($_FILES['post_add']) && $_FILES['post_add']!='')) { $file_prefix = time() + rand( 1, 100 )

我必须上传代码 此代码用于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'" );

    }
    }

}
$allowed_extensions=array(“gif”、“jpg”、“png”、“jpe”、“jpeg”);
如果((设置($\u文件['post\u add'])和&$\u文件['post\u add']!=''){
$file_prefix=time()+rand(1100);
$file\u前缀=“\u”;
定义(‘文件夹前缀’、日期(“Y-m”);
如果(!is_dir(ROOT_dir./uploads/posts/..FOLDER_PREFIX)){
@mkdir(ROOT_DIR./uploads/posts/..FOLDER_前缀,0777);
@chmod(ROOT_DIR./uploads/posts/..FOLDER_前缀,0777);
@mkdir(ROOT_DIR./uploads/posts/..FOLDER_PREFIX./thumbs),0777);
@chmod(ROOT_DIR./uploads/posts/.FOLDER_PREFIX./thumbs),0777);
}            
$config\u path\u image\u upload=ROOT\u DIR.“/uploads/posts/”.文件夹\u前缀./”;
$current_image='post_add';
$image=$\u文件[$current\u image]['tmp\u name'];
$image\u name=$\u文件[$current\u image]['name'];
$image\u size=$\u文件[$current\u image]['size'];
$error\u code=$\u文件[$current\u图像]['error'];
$img\u name\u arr=分解(“.”,$image\u name);
$type=totranslit(结束($img_name_arr));
如果($image\u name!=“”){
$curr\u key=key($img\u name\u arr);
未设置($img_name_arr[$curr_key]);
$image\u name=totranslit(内爆(“.”,$img\u name\u arr))。“$type;
}
if(在数组中(strtolower($type),$allowed_extensions)){
@移动上传的文件($image、$config\u path\u image\u upload.$file\u prefix.$image\u name);
如果(@file_存在($config_path_image_upload.$file_prefix.$image_name)){
@chmod($config\u path\u image\u upload.$file\u prefix.$image\u name,0666);
$row=$db->super_query(“选择COUNT(*)作为“.PREFIX”中的COUNT。”_图像,其中作者=“{$member_id[name]}”和新闻_id=“$idpost”);
如果(!$row['count'])){
$added_time=time()+($config['date_adjust']*60);
$inserts=文件夹\前缀。“/”$file\前缀。$image\名称;
$db->query(“插入到“.PREFIX.”图像(图像、作者、新闻标识、日期)值(“$inserts”、“{$member\u id[name]}”、“$idpost”、“$added\u time”);
}否则{
$row=$db->super_query(“从.PREFIX.中选择图像。”_图像,其中作者='{$member_id[name]}'和新闻_id='$idpost');
如果($row['images']==“”)$listimages=array();
else$listimages=explode(“| | |,$row['images]”);
foreach($listimages作为$dataimages){
如果($dataimages==文件夹\u前缀。“/”$file\u前缀.$image\u名称)$error\u image=“stop”;
}
如果($error\u image!=“stop”){
$listimages[]=文件夹前缀“/”$file\u前缀。$image\u名称;
$row['images']=内爆(“| | | |,$listimages”);
$db->query(“UPDATE”.PREFIX。”_imagesset images='{$row['images']}'其中author='{$member_id[name]}'和news_id='$idpost');
}
}
包括引擎目录。'/classes/thumb.class.php';
$tumb_ok=false;
$\u POST['make_thumb']=true;
$\u POST['make\u watermark']=$config['allow\u watermark'];
如果(isset($_POST['make_thumb'])){
$thumb=新缩略图($config\u path\u image\u upload.$file\u prefix.$image\u name);
如果($thumb->size\u auto($config['max\u image'],$\u POST['t\u seite'])){
$thumb->jpeg_质量($config['jpeg_质量]);
如果($config['allow_watermark']=“yes”和$u POST['make_watermark']=“yes”)$thumb->insert_watermark($config['max_watermark']);
$thumb->save($config\u path\u image\u upload.“thumbs/”$file\u prefix.$image\u name);
}
如果(@file_存在($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\u up\u side']=intval($config['max\u up\u side']);
如果($config['allow\u watermark']=“yes”和$u POST['make\u watermark']=“yes”)或$config['max\u up\u side']){
$thumb=新缩略图($config\u path\u image\u upload.$file\u prefix.$image\u name);
$thumb->jpeg_质量($config['jpeg_质量]);
如果($config['max\u up\u side'])$thumb->size\u auto($config['max\u up\u side']);
如果($config['allow_watermark']=“yes”和$u POST['make_watermark']=“yes”)$thumb->insert_watermark($config['max_watermark']);
$thumb->save($config\u path\u image\u upload.$file\u prefix.$image\u name);
}
$short\u story=preg\u replace('/^(.*?()*?$/is'、'$1'、$short\u story);
如果($tumb_ok)$short_story=”“.$short_story;
else$short_story=“”。$short_story;
$full_story=”“.$full_story;
$short\u story=addslashes($short\u story);
$full_story=addslashes($full_story);
$db->query(“UPDATE”.PREFIX.“\u post SET short\u story='$short\u story',full\u story='$full\u story',其中id='$idpost'”);
}
}
}

我写信给google translate

为什么你想在admin cp中设置代码的同时玩转代码?可以在系统设置中为文件和图像设置该选项,新版本的DLE设置将移动到用户组管理器

这与您的web服务器设置有关,不是Javascript选项。代码中的错误抑制运算符太多了。可以从Javascript服务器设置中删除并使Javascript帮助吗?