使用uploadify最新版本上传视频

时间:2012-05-21 05:46:26

标签: php javascript jquery uploadify

我想使用uploadify最新版本上传视频,但我失败了。

我的代码:

HTML:

<form  enctype="multipart/form-data" class="form-part" action="form.php" method="post">
  <input  class="uplodify" id="file_upload" type="file"/>
</form>

jQuery的:

$('#file_upload').uploadify({
        swf: 'uploadify/uploadify.swf',
        uploader: 'uploadify/uploadify.php',
        multi: true,
        //queueSizeLimit: 3,
        fileExt: '*.jpg;*.gif;*.png;*.mp4;*.mp3;*.avi;*.wmv;*.flv;',
        auto: true,
        onUploadStart: function(file) {
            console.log(file);
        },
        onUploadComplete: function(event, ID, fileObj, response, data) {

        },
        onUploadError : function(file, errorCode, errorMsg, errorString) {
            alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
        },
        onUploadSuccess : function(file, data, response) {
            console.log('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
        }
    });

PHP:

error_reporting(0);
$targetFolder = '/uploads'; // Relative to the root

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = dirname(dirname(__FILE__)) . $targetFolder;
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png', 'mp3', 'mp4', 'avi', 'flv', 'wmv'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);
    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);
        echo '1';
    } else {
        echo 'Invalid file type.';
    }
}

注意: console

中没有错误

onUploadSuccess() log is:文件easyhtm-wp.FLV已成功上传,回复为true:文件类型无效。

在此行之后立即在控制台中显示警告:

请帮助我。

感谢。

1 个答案:

答案 0 :(得分:2)

您将扩展区分大小写。 FLVflv不同。在比较之前将文件的扩展名转换为小写。

if( in_array( strtolower( $fileParts['extension'] ), $fileTypes ) ) {
    ...