用户如何将视频上传到我的网站?
Posted
技术标签:
【中文标题】用户如何将视频上传到我的网站?【英文标题】:How can user upload video to my website? 【发布时间】:2015-10-07 03:23:23 【问题描述】:我正在开发一个网站,我希望用户上传图片或视频。
<form enctype="multipart/form-data" action="upload.php" method="post">
<div id="filediv">
<input name="file[]" type="file" id="file"/>
</div>
<br/>
<input type="button" id="add_more" class="upload" value="Add More Files"/>
<input type="submit" value="Upload File" name="submit" id="upload" class="upload"/>
</form>
我的upload.php
确实将图像值存储在数据库中,就像我必须这样做来存储视频一样
uplaod.php
<?php
include "dbConfig.php";
if (isset($_POST['submit']))
$j = 0;
$name = $_FILES['file']['name'];
$target_path = "uploads/";
for ($i = 0; $i < count($_FILES['file']['name']); $i++)
$validextensions = array("jpeg", "jpg", "png", "mp3", "mp4", "wma");
$ext = explode('.', basename($_FILES['file']['name'][$i]));
$file_extension = end($ext);
//print_r(basename($_FILES['file']['name'][$i]));
$target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];
$j = $j + 1;
if (($_FILES["file"]["size"][$i] < 1024*1024*1024) && in_array($file_extension, $validextensions))
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path))
echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
$actual_image_name=$_FILES['file']['name'][$i];
mysqli_query($link,"INSERT INTO members(avatar) VALUES ('$actual_image_name')");
else
echo $j. ').<span id="error">please try again!.</span><br/><br/>';
else
echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
?>
这适用于上传图片,但不适用于上传视频。
【问题讨论】:
“工作正常”是什么意思? 可能是视频文件太大? - 检查您的错误日志 任务很不清楚。请指定您要上传的文件类型 你的代码和youtube没有关系 试试这个怎么样->下载一个小于2MB的视频,看看有没有上传? 【参考方案1】:PHP has several configuration options to limit resources consumed by scripts. By default, PHP is set to allow uploads of files with a size of 2MB or less.
Try increasing the following values in php.ini, for example:
memory_limit = 32M
upload_max_filesize = 24M
post_max_size = 32M
If the upload_max_filesize is larger than post_max_size, you must increase post_max_size so that it is bigger than upload_max_size.
If the value of post_max_size is larger than memory_limit, you must increase memory_limit so that it is larger than post_max_size.
There are multiple ways to edit php.ini
希望对你有帮助
【讨论】:
【参考方案2】:默认情况下,最大upload_limit 设置为2 MB。因此,如果您尝试上传任何大小超过 2 MB 的文件,它将失败。
要更改它,请编辑您的php.ini
并设置
upload_max_filesize = 40M ; you may set it according to your need
【讨论】:
以上是关于用户如何将视频上传到我的网站?的主要内容,如果未能解决你的问题,请参考以下文章
使用 Youtube Api v3 和 oauth2 将视频上传到我的 Youtube 频道,无需用户身份验证
允许用户使用 youtube API v3 将视频上传到我的频道
未经用户同意使用 youtube Data API V3 将视频自动上传到我的帐户