0

如何在 IE 中也解决这个问题?:

$(document).ready(function() {
    //i want to hide the <input type="file"...>

和文件资源管理器打开宽度是图像点击

    $("#preview").html('<img src="uploads/default.png" class="preview" />').click(function() {
        $('#imgfile').click();
    });

firefox、ghrome、safari 和 opera 都可以

    $('#imgfile').bind('change', function() {
        $("#preview").html('');
        $("#preview").html('<img src="loader.gif" alt="Uploading...."/>');

...但在 Internet Explorer 中,ajaxForm-function 不起作用并保持显示加载图像:

        $("#imageform").ajaxForm({
            target: '#preview'
        }).submit();
    });
    $("#imgfile").hide();
});

并且有html代码:

<div style="width:600px">
    <form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'>
        <input type="file" name="imgfile" id="imgfile" />
    </form>
    <div id='preview'></div>
</div>

和CSS代码:

.preview {
    width:100px;
    height:100px;
    border:solid 1px #dedede;
    padding:0px;
    margin:0px;
    color:#cc0000;
    font-size:12px
}

..和 ajaimage.php 看起来像:

<?php
$path = "uploads/";
$valid_formats = array("jpg", "png", "gif", "bmp");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
    $name = $_FILES['imgfile']['name'];
    $size = $_FILES['imgfile']['size'];
    if(strlen($name)) {
        list($txt, $ext) = explode(".", $name);
        if(in_array($ext,$valid_formats)) {
            if($size<(1024*1024)) {
                $actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
                $tmp = $_FILES['imgfile']['tmp_name'];
                if(move_uploaded_file($tmp, $path.$actual_image_name))
                    echo '<img src="uploads/'.$actual_image_name.'" class="preview" />';
                else echo "failed";
            } else echo "Image file size max 1 MB";
        } else echo "Invalid file format..";    
    } else echo "Please select image..!";
}
?>

谢谢

4

0 回答 0