使用Uplodify上传文件有时会工作,有时则不会

时间:2013-09-01 07:17:41

标签: php file-upload uploadify

我在我的网站上安装了Uploadify UI,因此我可以允许用户将文件上传到我的网站。它现在正在工作,但问题是它有时上传文件,有时它不上传。所以我可以上传一个png文件,它不会有任何问题。但是当我上传excel文件时,它会允许一些上传,一些工作允许它。

我不确定如何检查导致问题的原因。

我试图在'debug'上关闭debuger:true但是这并没有给我任何线索。我也查看了我的php日志,那里没有错误/警告。

我不确定我还能检查什么,但我会为此澄清任何类型的帮助。

以下是我设置的javascript代码

<?php $timestamp = time();?>

    <script type="text/javascript">
    $(function() {
        $('#file_upload').uploadify({
                'formData'     : {
                'timestamp' : '<?php echo $timestamp;?>',
                'token'     : '<?php echo md5($timestamp);?>',
                'upload_path': 'ticketing_center/',
                'allowed_extentions': 'jpg,jpeg,gif,PNG,JPG,png,JPEG, jpeg,zip,rar,doc,docx,cvs,xls,xlsx,txt'
            },
            'auto' : true,
            'debug' : true,
            'swf'      : '../../includes/uploadify.swf',
            'uploader' : '../../includes/uploadify.php',
            'fileSizeLimit' : '50MB',
            'fileTypeExts' : '*.gif; *.jpg; *.JPG; *.png; *.PNG; *.JPEG; *.jpeg; *.zip; *.rar; *.doc; *.docx; *.cvs; *.xls; *.xlsx; *.txt;',
            'onUploadSuccess' : function(file, data, response) {
                if(data != 'INVALID'){
                    $('#attached_files').append('<input type="hidden" name="attachments[]" value="'+ $.trim(data) +'" />');
                } else {
                    alert('Invalid File Type');
                }
            }

        });
    });
</script>

以下是我的PHP脚本

<?php
    $targetFolder = '';
    $verifyToken = '100';
    $actualToken = '';
    $fileTypes = array('jpg','jpeg','gif','png');

    if(isset($_POST['upload_path'])){
        $targetFolder = $_POST['upload_path'];
    }

    if(isset($_POST['timestamp'])){
        $verifyToken = md5($_POST['timestamp']);
    }

    if(isset($_POST['token'])){
    $actualToken = $_POST['token'];
    }

    if(isset($_POST['allowed_extentions'])){

        $types = explode(',', $_POST['allowed_extentions']);

        if(count($types) > 0 ){
            $fileTypes = $types;
        }
    }


    if (!empty($_FILES) && $actualToken == $verifyToken) {
        $tempFile = $_FILES['Filedata']['tmp_name'];
        $targetPath =  ROOT_FIXED . UPLOAD_DIR . $targetFolder;   //$_SERVER['DOCUMENT_ROOT']
        $targetPath = str_replace( "//", "/", $targetPath);
        $new_filename = USER_ID . '_' . time() . '_' . str_replace(" ", "_", $_FILES['Filedata']['name']);
        $targetFile = $targetPath . $new_filename;

        // Validate the file type
        //$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
        $fileParts = pathinfo($new_filename);  //str_replace(" ", "_", $_FILES['Filedata']['name'])

        if (in_array($fileParts['extension'],$fileTypes)) {
            move_uploaded_file($tempFile,$targetFile);
            echo trim($new_filename);
        } else {
            echo 'INVALID';
        }
    }
    ?>

感谢您的时间和帮助

1 个答案:

答案 0 :(得分:1)

我不明白为什么人们会在没有评论的情况下向下投票,这有助于您理解原因。但任何方式可以帮助其他人遇到同样的问题。这是解决方案

我的php.ini文件中的配置被设置为低限制。最大上传文件设置为2M

转到php.ini并找到

  • upload_max_filesize - 设置为50M

  • post_max_size - 设置为50M

  • max_execution_time - 设置为120

  • max_input_time - 设置为50

重启我们的apache,现在你应该能够上传大小达50MB的文件