文件上传不适用于较大的文件

时间:2012-06-21 14:25:23

标签: php file-upload

我正在尝试上传.zip文件。它适用于小文件。但我可以上传> 2MB的文件。当我尝试上传文件>左下角的2 MB谷歌浏览器显示为(uploadin: - %)其中 - 是一个不喜欢10.但它在14%之后被卡住了。一段时间后,它显示错误,如“错误101(net :: ERR_CONNECTION_RESET):连接已重置。”此网页不可用。

请帮帮我

这是表格代码

<form name="addnewitem" id="addnewitem" method="post" enctype="multipart/form-data">
                <?php if (($succ==0) && ($message!="")) { echo "<div class='error'>".$message."</div>"; } ?>
                <?php if ($msg!="") { echo "<div class='success'>".$msg."</div>"; } ?>
                <?php if ($msg1!="") { echo "<div class='error'>".$msg1."</div>"; } ?>
                <div class="list-item">

                        <div class="form">
                            <h2>Name & Description</h2>
                            <div class="row">
                                <div class="left">
                                    <label>Item Title:</label>
                                </div>
                                <div class="right">
                                    <input name="listitemname" id="listitemname" type="text" class="input" maxlength="50" value="<?php echo $_POST['listitemname']; ?>" />
                                    <em>Maximum 50 characters</em>
                                </div>
                            </div>
                            <div class="row">
                                <div class="left">
                                    <label>
                                        Item Description:
                                    </label></div>
                                <div class="right">
                                    <textarea name="itemdescription" id="itemdescription" cols="10" rows="5"><?php echo $_POST['itemdescription'];?></textarea>
                                    <em>Maximum 600 characters</em>
                                </div>
                            </div>
                        </div>

                    <div class="form">
                        <h2>
                            Item Files & Preview
                        </h2>
                        <div class="row">
                            <div class="left">
                                <label>
                                    Item Thumbnail:
                                </label>
                            </div>
                <div class="right"><input type="file" name="thumbnailimage" id="thumbnailimage" class="input" />
                                <em>JPG or PNG, 80 x 80 Thumbail</em>
                            </div>
                        </div>
                        <div class="row">
                            <div class="left">
                                <label>
                                    Item Rollover Preview:
                                </label></div>
                            <div class="right"><input type="file" name="rolloverimage" id="rolloverimage" class="input" />
                                <em>JPG or PNG, 190 x 190 Preview Image</em>
                            </div>
                        </div>
                                                    <div class="row">
                            <div class="left">
                                <label>
                                    Screenshot image 1:
                                </label></div>
                            <div class="right"><input type="file" name="themepreview1" id="themepreview1" class="input" />
                                <em>JPG or PNG, 420 x 420 Image Screenshot ( Required )</em>
                            </div>
                        </div>
                                                                    <div class="row">
                            <div class="left">
                                <label>
                                    Screenshot image 2:
                                </label></div>
                            <div class="right"><input type="file" name="themepreview2" id="themepreview2" class="input" />
                                <em>JPG or PNG, 420 x 420 Image Screenshot ( Optional )</em>
                            </div>
                        </div>
                                                                    <div class="row">
                            <div class="left">
                                <label>
                                    Screenshot image 3:
                                </label></div>
                            <div class="right"><input type="file" name="themepreview3" id="themepreview3" class="input" />
                                <em>JPG or PNG, 420 x 420 Image Screenshot ( Optional )</em>
                            </div>
                        </div>
                                                                    <div class="row">
                            <div class="left">
                                <label>
                                    Screenshot image 4:
                                </label></div>
                            <div class="right"><input type="file" name="themepreview4" id="themepreview4" class="input" />
                                <em>JPG or PNG, 420 x 420 Image Screenshot ( Optional )</em>
                            </div>
                        </div>
                                                                                <div class="row">
                            <div class="left">
                                <label>
                                    Item Zip File:
                                </label></div>
                            <div class="right"><input type="file" name="itemfile" id="itemfile" class="input" />
                                <em>.ZIP File Only </em>
                            </div>
                        </div>

                                            <div class="row">
                            <div class="left">
                                <label>Demo URL:</label>
                            </div>
                            <div class="right">
                                <input name="demourl" id="demourl" type="text" class="input" value="<?php echo $_POST['demourl']; ?>" />
                                <em>Enter the www.themepreviewurl.com here for the item Live Preview</em>
                            </div>
                        </div>
                        </div>
                    <div class="form">
                        <h2>
                            Category & Attributes
                        </h2>
                        <div class="row">
                            <div class="left">
                                <label>
                                    Category:
                                </label></div>
                            <div class="right">
                                <?php
                                    $getmaincategories = "SELECT category_name,category_id FROM ".$tbl_main_categories." WHERE category_status = 1";
                                    $exec_getmaincategories = mysql_query($getmaincategories);
                                    echo "<select name='categoryname' id='categoryname'>";
                                    echo "<option value='' >Select a Category Now</option>";
                                    while($rows_getmaincategories = mysql_fetch_array($exec_getmaincategories)) {
                                        $getsubcategories = "SELECT sub_category_name,sub_category_hash FROM ".$tbl_sub_categories." WHERE sub_category_status=1 AND     category_id=".$rows_getmaincategories['category_id'];
                                        $exec_getsubcategories = mysql_query($getsubcategories);
                                        echo "<option disabled='disabled' value='".$rows_getmaincategories['category_id']."'>".$rows_getmaincategories['category_name']."</option>";
                                        while($rows_getsubcategories = mysql_fetch_array($exec_getsubcategories)) {
                                        if ($_REQUEST['categoryname'] == $rows_getsubcategories['sub_category_hash']) { echo $selectedvalue = "selected='selected'"; } 
                                            echo "<option value='".$rows_getsubcategories['sub_category_hash']."' style='padding-right:inherit' $selectedvalue>&nbsp;&nbsp;&nbsp;&nbsp;-".$rows_getsubcategories['sub_category_name']."</option>";
                                        }
                                    }
                                    echo "</select>";
                                ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="left">
                                <label>
                                    Compatible Browsers:<br />
                                    use 'ctrl' to select multiples
                                </label></div>
                            <div class="right">
                                <select multiple="multiple" class="select" name="browsercompatiable[]" id="browsercompatiable[]">
                                    <option value="">Select</option>
                                    <option value="ie7" <?php if ($_REQUEST['browsercompatiable'] == "ie7") echo "selected='selected'"; ?>>IE7</option>
                                    <option value="ie8" <?php if ($_REQUEST['browsercompatiable'] == "ie8") echo "selected='selected'"; ?>>IE8</option>
                                    <option value="ie9" <?php if ($_REQUEST['browsercompatiable'] == "ie9") echo "selected='selected'"; ?>>IE9</option>
                                    <option value="firefox" <?php if ($_REQUEST['browsercompatiable'] == "firefox") echo "selected='selected'"; ?>>Firefox</option>
                                    <option value="safari" <?php if ($_REQUEST['browsercompatiable'] == "safari") echo "selected='selected'"; ?>>Safari</option>
                                    <option value="chrome" <?php if ($_REQUEST['browsercompatiable'] == "chrome") echo "selected='selected'"; ?>>Chrome</option>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="left">
                                <label>
                                    Files Includes:<br />
                                    Use 'ctrl' to select multiples
                                </label></div>
                            <div class="right">
                                <select multiple="multiple" size="5" class="select" name="filesinclude[]" id="filesinclude[]">
                                    <option value="">Select</option>
                                    <option value="ie7" <?php if ($_REQUEST['filesinclude'] == "ie7") echo "selected='selected'"; ?>>PSD Files</option>
                                    <option value="ie8" <?php if ($_REQUEST['filesinclude'] == "ie8") echo "selected='selected'"; ?>>Documentation</option>
                                    <option value="ie9" <?php if ($_REQUEST['filesinclude'] == "ie9") echo "selected='selected'"; ?>>Multiple Layouts</option>
                                    <option value="firefox" <?php if ($_REQUEST['filesinclude'] == "firefox") echo "selected='selected'"; ?>>Multiple Colour Options</option>
                                    <option value="safari" <?php if ($_REQUEST['filesinclude'] == "safari") echo "selected='selected'"; ?>>Video Help Files</option>
                                    <option value="chrome" <?php if ($_REQUEST['filesinclude'] == "chrome") echo "selected='selected'"; ?>>Other</option>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="left">
                                <label>
                                    Columns:
                                </label></div>
                            <div class="right">
                                <select name="noofcolumns" id="noofcolumns">
                                <option value="">Select</option>
                                <option value="1" <?php if ($_REQUEST['noofcolumns'] == "1") echo "selected='selected'"; ?>>1</option>
                                <option value="2" <?php if ($_REQUEST['noofcolumns'] == "2") echo "selected='selected'"; ?>>2</option>
                                <option value="3" <?php if ($_REQUEST['noofcolumns'] == "3") echo "selected='selected'"; ?>>3</option>
                                <option value="4" <?php if ($_REQUEST['noofcolumns'] == "4") echo "selected='selected'"; ?>>4</option>
                                <option value="5" <?php if ($_REQUEST['noofcolumns'] == "5") echo "selected='selected'"; ?>>5</option>                      
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="left">
                                <label>
                                    Layout:
                                </label></div>
                            <div class="right">
                                <select name="layout" id="layout">
                                <option value="">Select</option>
                                <option value="1" <?php if ($_REQUEST['layout'] == "1") echo "selected='selected'"; ?>>1</option>
                                <option value="2" <?php if ($_REQUEST['layout'] == "2") echo "selected='selected'"; ?>>2</option>
                                <option value="3" <?php if ($_REQUEST['layout'] == "3") echo "selected='selected'"; ?>>3</option>
                                <option value="4" <?php if ($_REQUEST['layout'] == "4") echo "selected='selected'"; ?>>4</option>
                                <option value="5" <?php if ($_REQUEST['layout'] == "5") echo "selected='selected'"; ?>>5</option>                       
                                </select>
                                <em>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id arcu vitae eros molestie ultricies ut sit amet nisi. Nulla facilisi.</em>
                            </div>
                        </div>

                    </div>
                    <div class="form">
                        <h2>Tags</h2>
                        <div class="row">
                            <div class="left">
                                <label>Tags:</label>
                            </div>
                            <div class="right">
                                <textarea name="itemtags" id="itemtags" cols="10" rows="5"><?php echo $_POST['itemtags']; ?></textarea>
                                <em>Maximum 50 characteres</em>
                            </div>
                        </div>
                    </div>
                    <div class="botton">
                        <input name="additem" id="additem" type="submit" value="Upload Now" class="btn" />
                    </div>              
                </div>
                </form>

我想在下面显示的.zip字段中上传&gt; 3MB文件

<div class="right"><input type="file" name="itemfile" id="itemfile" class="input" />
                                <em>.ZIP File Only </em>
                            </div>

4 个答案:

答案 0 :(得分:5)

检查php.ini中的upload_max_filesize,max_input_time, post_max_size

如果文件大小非常大,您可能还需要使用memory_limit。

答案 1 :(得分:1)

更改php.ini更改大小并测试脚本。(php.ini驻留在php安装目录中)

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

upload_max_filesize = Required_size M

答案 2 :(得分:1)

请检查服务器中的“max_input_time”选项是否太低,这可能就是PHP让你失望的原因。否则,它可能是与服务器/网络基础设施相关的问题:

echo ini_get('max_input_time');

如果从这里得到-1,很可能不是PHP会让你失望,而是循环中的其他东西。它可以是通往服务器的任何硬件,但很可能是服务器本身或服务器上的某些东西...

答案 3 :(得分:0)

对于大型文件,如果您不想处理配置服务器设置(特别是如果您使用的是共享主机或其他不能完全控制服务器的主机),一个可能的解决方案是将上传内容交给第三方服务。

例如,您可以让表单直接发布到Amazon S3(http://s3.amazonaws.com/doc/s3-example-code/post/post_sample.html)或使用Filepicker.io等服务

完全披露:我在Filepicker.io工作,但想帮助处理大文件上传问题的人