简体   繁体   English

PHP上传视频htaccess MIME TYPE

[英]PHP Uploading a video htaccess MIME TYPE

for the past week I have been trying to do a file upload with videos, I did them with images and those work fine but my videos were not uploading. 在过去的一周里,我一直在尝试使用视频上传文件,我用图片做了这些,而且工作正常,但我的视频没有上传。 A friend of mine suggested I declare the MIME TYPES in my .htaccess file and I tried that but it didnt work, is the syntax wrong? 我的一个朋友建议我在我的.htaccess文件中声明MIME TYPES并尝试了但是它没有用,语法错了吗? or am I going about this the wrong way? 或者我是以错误的方式来做这件事的?

Here is my .htacess syntax 这是我的.htacess语法

AddType video/avi .avi
AddType video/quicktime .mov
AddType video/mpeg .mpeg .mpg
AddType video/mp4 .mp4

and the PHP for file uploading.... 以及用于文件上传的PHP ....

move_uploaded_file($_FILES["video"]["tmp_name"],
"../upload/" . $id . $title . date("Ymd") . $_FILES["video"]["name"]);
$class->insertvideo($video);

First off you don't need to use AddType unless you want a certain file type to be executed by the server instead of directly being output directly. 首先,除非您希望服务器执行某种文件类型而不是直接直接输出,否则不需要使用AddType。

Second. 第二。 You should make sure the "video" key is in $_FILES before accessing it. 在访问之前,您应确保“video”键位于$ _FILES中。

Are your your looking in the right directory? 您正在寻找合适的目录吗? Make sure you are looking in the parent directory of wherever you uploaded the file. 确保查看上载文件的父目录。

Try the following code to be sure the file is actually being uploaded. 请尝试以下代码以确保文件实际上传。

if(array_key_exists('video',$_FILES)
{
    if($_FILES['video']['error']==UPLOAD_ERROR_OK)
    {
        move_uploaded_file($_FILES['video']['tmp_name'],'../upload/'.basename($_FILES['video']['name']);
        echo 'success';
    }
    else
    {
        throw new Exception('error detected');
    }
}
else
{
    throw new Exception('video not in $_FILES array key.');
}

Also be sure your upload form contains the correct encryption type. 还要确保您的上传表单包含正确的加密类型。

<form method="post" enctype="multipart/form-data">
    <input type="file" name="video" />
    <input type="submit" value="submit" />
</form>

Run a phpinfo() and get your upload_max_filesize. 运行phpinfo()并获取upload_max_filesize。 It usually defaults to 2MB, which is probably too small for your videos. 它通常默认为2MB,这对于您的视频来说可能太小了。 Also you execution time will need to be set up long enough for the file to upload. 此外,您需要将执行时间设置得足够长,以便上传文件。

These have to be set in the php.ini. 这些必须在php.ini中设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM