除了chrome之外,uploadify onsuccess函数不会被触发

时间:2014-08-21 12:44:35

标签: jquery uploadify

我有uplodify设置,目前在wamp(localhost)上工作得很好(firefox ie和chrome)。我注意到,在我将文件添加到我的网站后,uploadify onsuccess函数无法在firefox中启动,即。只有铬似乎有效。我似乎无法找到任何错误,因为它在我的本地计算机上运行良好。有人可以帮忙吗?

JAVASCRIPT

$('#fileupload').uploadify({
            'swf': 'scripts/uploadify/uploadify.swf',
            'uploader': 'cgi/uploadify.php',
            'buttonText': 'Choose Picture',
            'wmode': 'transparent',
            'buttonClass': 'upbutton',
            'buttonImage': false,                    
            'multi': false,
            'preventCaching': true,
            'fileSizeLimit': '500KB',
            'fileTypeExts': '*.jpg; *.JPG; *.jpeg',
            'fileTypeDesc': 'Image Files',                    
            'successTimeout' : 5,
            'width'    : 134,

            'onUploadStart':function(file) { 
                $('#fileupload').css('opacity', '0');
                $('#progress').css('display', 'block');
            },
            'onUploadSuccess': function(file, data, response) { 
                var obj = eval('(' + data + ')');
                if ( obj.success ) { 
                    $('#passport-photo').attr('src', obj.path);
                    $('#path').val(obj.path);
                    $('#pictureHolder').attr('style', 'width:100%; height:153px; margin: 0px 0px 10px; border: thin solid lightgray;overflow: hidden;');
                }else { 
                    var stats = this.getStats();
                    this.setStats({successful_uploads: stats.successful_uploads - 1});
                    alert("Picture upload failed: "+obj.error_msg);
                }
            },
            'onUploadComplete': function(file) {
                $('#fileupload').css('opacity', '1');
                $('#progress').css('display', 'none');
                $('#progress').css('width', '0%');
            },
            'onSelectError': function(file, errorCode, errorMsg) {
                switch(errorCode){
                    case INVALID_FILETYPE : alert('The image must be in jpeg format!');
                    case FILE_EXCEEDS_SIZE_LIMIT: alert('The image size is too large!');
                    default: alert('An Error occured!');
                }
            },
            'onUploadError': function(file, errorCode, errorMsg, errorString) {
                switch(errorCode){
                    case INVALID_FILETYPE : alert('The image must be in jpeg format!');
                    case FILE_EXCEEDS_SIZE_LIMIT: alert('The image size is too large!');
                    default: alert('An Error occured!');
                }
            },
            'onUploadProgress': function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
                var percentcomp = (100 * (totalBytesTotal / totalBytesUploaded)).toFixed(0);
                var comp = percentcomp+'%';
                $('.progress-bar').css('width',comp);
            },
            'onFallback': function() {
                alert('Flash Player is required. Please Download & Install the latest flash player');
            }
        });

PHP

    // Define a destination
    $targetFolder = '../uploads/images'; // Relative to the root
    //$verifyToken = md5('unique_salt' . $_POST['timestamp']);
    header("Content-type: application/json; charset=utf-8");

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

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

    $targetFile = getFileName($fileParts['extension']);

    while (file_exists($targetFile)) {
        $targetFile = getFileName($fileParts['extension']);
    }

    $size = getimagesize($tempFile);

    if($size[0] < 132 || $size[0] > 136 || $size[1] < 152 || $size[1] > 156) {
        $data = array(
            "path" =>"",
            "success" => FALSE,
            "error_msg" => "Picture must be 134x154 pixels."
        );
        echo json_encode($data);
    }elseif(in_array($fileParts['extension'], $fileTypes)) {
        move_uploaded_file($tempFile, $targetFile);
        $path = str_replace("cgi/uploadify.php", "", $_SERVER['SCRIPT_NAME']);       

        $data = array(
            "path" => $path . str_replace("../", "", $targetFile),
            "success" => TRUE,
            "error_msg" => ""
        );
        echo json_encode($data);
    } else {
        $data = array(
            "path" =>"",
            "success" => FALSE,
            "error_msg" => "File type is invalid"
        );
        echo json_encode($data);
    }
}

0 个答案:

没有答案