简体   繁体   中英

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? or am I going about this the wrong way?

Here is my .htacess syntax

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

and the PHP for file uploading....

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.

Second. You should make sure the "video" key is in $_FILES before accessing it.

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. It usually defaults to 2MB, which is probably too small for your videos. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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