【问题标题】:Uploadify uploads pictures and nothing elseUploadify 上传图片,仅此而已
【发布时间】:2014-03-23 01:36:54
【问题描述】:

我想将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.';
}

}

总结

上传图片 - 是的,没问题

上传其他任何东西 - 不,为什么以及如何让它工作?

提前致谢。

【问题讨论】:

    标签: php file-upload upload uploadify


    【解决方案1】:

    这两个部分限制上传图片(和 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.';
    }
    

    【讨论】:

    • 是的,我知道,问题是它不会上传 mp3... 它会上传图片 (*.gif; *.jpg; *.png; *.png;) 但完全忽略mp3 文件。上传时指标显示为 100%,但在上传文件夹中没有显示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多