如何设置视频文件大小上传的限制 [英] How to set limit for video file size upload

查看:471
本文介绍了如何设置视频文件大小上传的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个webapp,允许用户将视频上传到服务器进行共享,但为了最大限度地减少存储空间,我想为每个用户设置一个限制为视频文件大小上传。

但是当我在保存和刷新页面后添加了一个代码片段进行修改,它变为空白,即它没有在UI上显示任何内容进行上传。

请参阅下面的代码





if($ _POST ['video_type'] =='local')

{


$ maxsize = 5242880; // 5MB



//检查文件大小

if(($ _ FILES ['file'] ['size']> = $ maxsize)||($ _FILES [file] [size] == 0)){

echo文件太大。文件必须小于5MB。;

} else {

//上传

$ file_path ='http://'。$_SERVER ['SERVER_NAME']。 dirname($ _ SERVER ['REQUEST_URI'])。'/ uploads /';

echo上传成功。;

}

}



/ * $ file_path ='http://'。$_SERVER ['SERVER_NAME']。目录名($ _ SERVER [ REQUEST_URI])/上传/。 * /



$ video_url = $ file_path。$ _ POST ['video_file_name'];



$ file_name = str_replace(, - ,$ _ FILES ['video_thumbnail'] ['name']);



$ video_thumbnail = rand(0,99999)。 _。$ file_name;



//主图像

$ tpath1 ='images /'.$ video_thumbnail;

$ pic1 = compress_image($ _ FILES [video_thumbnail] [tmp_name],$ tpath1,80);



// Thumb Image

$ thumbpath ='images / thumbs /'.$ video_thumbnail;

$ thumb_pic1 = create_thumb_image($ tpath1,$ thumbpath,'200','200');



$ video_id ='';

}



请帮助



我尝试了什么:



我试着在google上搜索并询问on developer fussion

Hi, i have a webapp that allows users to upload video to server for sharing, but inorder to minimize storage usage i want to set a limi to video file size upload per user.
But when i added a code snippet for the modification after saving and refreshing the page it goes blank i.e it does not show anything on the UI for uploading.
See the code below


if ($_POST['video_type']=='local')
{

$maxsize = 5242880; // 5MB

// Check file size
if(($_FILES['file']['size'] >= $maxsize) || ($_FILES["file"]["size"] == 0)) {
echo "File too large. File must be less than 5MB.";
}else{
// Upload
$file_path = 'http://'.$_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']).'/uploads/';
echo "Upload successfully.";
}
}

/* $file_path = 'http://'.$_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']).'/uploads/'; */

$video_url=$file_path.$_POST['video_file_name'];

$file_name= str_replace(" ","-",$_FILES['video_thumbnail']['name']);

$video_thumbnail=rand(0,99999)."_".$file_name;

//Main Image
$tpath1='images/'.$video_thumbnail;
$pic1=compress_image($_FILES["video_thumbnail"]["tmp_name"], $tpath1, 80);

//Thumb Image
$thumbpath='images/thumbs/'.$video_thumbnail;
$thumb_pic1=create_thumb_image($tpath1,$thumbpath,'200','200');

$video_id='';
}

Kindly help

What I have tried:

I tried searching on google and asking on developer fussion

推荐答案

_POST ['video_type'] =='local')

{


_POST['video_type']=='local')
{


maxsize = 5242880; // 5MB



//检查文件大小

if((
maxsize = 5242880; // 5MB

// Check file size
if((


_FILES ['file '] ['size']> =
_FILES['file']['size'] >=


这篇关于如何设置视频文件大小上传的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆