文件上传无法在IE8,IE9中运行

时间:2013-04-19 18:13:33

标签: php internet-explorer

我正在努力解决这个问题,到目前为止我没有运气。

我的文件上传适用于Chrome,Mozilla,Safari,而不是IE 8或9.它只是在Internet Explorer中挂起,直到它超时。代码的工作原理如下。

在这里,我正在寻找错误代码“0”,这意味着它是成功的。如果用户做了什么,但文档选择它会执行下面的代码..如果它是一个文档,它将转到代码的else部分。

对于第一部分..我在我的变量中设置了新文件路径。检查它是否未上传,如果没有,则向用户发送消息。如果成功,请将一些值插入表中。然后我使用我的函数move_uploaded_file将临时文件移动到我的目录。如果它是一个文档,那么我在else部分下面执行代码。我在哪里错了?任何想法都有帮助。

这是我的代码。

if ($_FILES['image']['error'] == 0) {

    if ($_POST['type'] != 'document') {

        $newFile = "/var/www/localhost/htdocs/digital-materials/images/products/".basename($_FILES['image']['name']);

        if (!move_uploaded_file($_FILES['image']['tmp_name'],$newFile)) {
            echo "<h1>Error uploading file ".$_FILES['image']['name']."</h1>$newFile<br />\n";
        } else {
            error_reporting(E_ALL);
            $escapedPost = array_map('mysql_real_escape_string', $_POST);
            extract($escapedPost);
            $sql = "INSERT INTO digital_materials (`itemName`,`itemDesc`,`imageURL`,`language`,`category`,`size`,`flagDesc`,`type`,`description`,`fileURL`) VALUES ('$itemName','$itemDesc','".basename($_FILES['image']['name'])."','$language','$category','".basename($_FILES['image']['size'])."','$itemDesc','$category','$itemDesc','".basename($_FILES['image']['name'])."')";
            $res = mysql_query($sql);
            move_uploaded_file($_FILES['image']['tmp_name'],$newFile);
            echo "<h1>File has been uploaded</h1><br />\n";
        }

    } else {

        print_r($_FILES);
        $newFile = "/var/www/localhost/htdocs/digital-materials/documents/".basename($_FILES['image']['name']);
        $file = $_FILES['image']['tmp_name'];
        move_uploaded_file($file,$newFile);

    }
}

表单代码如下

<form method='post' action='digital-materials-admin.php' enctype='multipart/form-data'>
            <input type='hidden' name='newItem' value='1' />
            <div class='add-new-input'>
                <div>Item Name:</div><input type='text' name='itemName' />
            </div>
            <div class='add-new-input'>
                <div>File:</div><input type='file' name='image' />
            </div>
            <div class='add-new-input'>
                <div>Type:</div>
                    <select name='type'>
                        <option value='default'>Please Select a Type</option>
                        <option value='image'>Image</option>
                        <option value='Photos'>Photo</option>
                        <option value='Logos'>Logo</option>
                        <option value='document'>Document</option>
                    </select>
            </div>
            <div id='typeSelect'></div>
            <div class='add-new-input'>
            <div>Category</div>
                <select name='category'>
                    <option value='default'>Please Select a Category</option>
                    <option value='Logos'>Logos</option>
                    <option value='Presentations'>Presentations</option>
                    <option value='Photos'>Photos</option>
                    <option value='PDF'>PDF</option>
                    <option value='CAD'>Cad Drawing</option>
                    <option value='Word'>Word Documents</option>
                    <option value='Spreadsheets'>Spreadsheets</option>
                </select>
            </div>
            <div id='categorySelect'></div>
            <div class='add-new-input'>
                <div>Item Description:</div><textarea rows='3' cols='40' name='itemDesc'></textarea>
            </div>
            <div class='add-new-input'>
                <div>Language:</div><input type='text' name='language' id='language' />
            </div>
            <div class='add-new-input'>
                <div>Flag Text:</div><input type='text' name='flagDesc' />
            </div>
            <div class='add-new-input'>
                <input type='submit' value='Add Item' id='submit-button' />
            </div>
        </form>

Css代码

#imageWarn {
    width: 300px;
    position: relative;
    left: 200px;
    color: red;
    font-size: 12px;
    padding-bottom: 15px;
}

.add-new-input {
    vertical-align:top;
    padding-bottom:10px;
}
.add-new-input input, textarea, select {
    width:300px;
}
.add-new-input div {
    width:200px;
    font-size:12pt;
    clear:none;
    display:inline-block;
    vertical-align:top;
}
#submit-button {
    width:100px;
}

1 个答案:

答案 0 :(得分:0)

尝试将此添加到您的表单

<input type="hidden" name="MAX_FILE_SIZE" value="MaxFileSizeInBytes">