Uploadify上传图片,没有别的

时间:2014-03-23 01:36:54

标签: php file-upload upload uploadify

我想将uploadify用于除图像之外的其他文件类型,但我无法让它工作。它上传任何类型的图像没有问题。当我尝试上传任何其他内容时,指示器显示100%,但上传文件夹中没有要查找的文件(仅限图片)。

index.php文件:

<script type="text/javascript">
    <?php $timestamp = time();?>
    $(function() {
        $('#file_upload').uploadify({
                            'checkExisting' : '/Bcp/uploadify/check-exists.php',
            'formData'     : {
                'timestamp' : '<?php echo $timestamp;?>',
                'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
            },
            'swf'      : 'uploadify.swf',
            'uploader' : 'uploadify.php',
                            'fileSizeLimit' : '50000KB',
                            'fileTypeExts' : '*.gif; *.jpg; *.png; *.png; *.mp3',
                            'fileTypeDesc' : 'Images and music'

        });
    });
</script>

uploadify.php文件:

$targetFolder = '/bcp/uploadify/uploads_pics'; // Relative to the root

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png', 'mp3'); // 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.';
}

}

摘要

上传图片 - 是的,没问题

上传其他内容 - 不,为什么以及如何让它发挥作用?

提前致谢。

1 个答案:

答案 0 :(得分:0)

这两个部分限制上传到图像(和mp3)。他们很可能是你的问题,应该很容易剥离。

'fileTypeExts' : '*.gif; *.jpg; *.png; *.png; *.mp3',

$fileTypes = array('jpg','jpeg','gif','png', 'mp3'); // 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.';
}