文件上传限制为1MB?

时间:2010-03-01 22:37:20

标签: php mysql cpanel

我无法理解为什么我的服务器不接受大于1MB的文件。我正在使用cpanel,我的主持人告诉我,我无法直接编辑我的php.ini文件。

我的上传代码:

<?php
if (array_key_exists('uploadfile', $_POST)) {
    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];

    $fp      = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);

    if (!get_magic_quotes_gpc()) {
        $fileName = addslashes($fileName);
    }

    mysql_query("INSERT INTO tbl_vehiclefiles (`veh_id`,`name`,`type`,`size`,`content`)
VALUES ('$veh_id', '$fileName', '$fileType', '$fileSize','$content')");

    echo '<b>File Upload</b><p>Thank you. The file has been successfully uploaded.

<p><img src="resources/spacer.gif" alt="" width="300px" height="5px" /><p><o>

<i><u>Name:</u>&nbsp;' . $fileName . '<p><i><u>Size:</u>&nbsp;' . $fileSize . 'k' . '<p><u>Type:</u>&nbsp;' . $fileType . '</i><p><p><img src="resources/spacer.gif" alt="" width="300px" height="5px" />';

    $file_id = mysql_insert_id();

    echo "</i><p><a href='managevehicle.php?id=$veh_id' class='form'>Manage details</a><p>
         <a href='viewfile2.php?id=$file_id' class='form'>View details</a><p>";
    exit;
}
?>      

<b>File Upload</b></p>
   <p>
     <input type="hidden" name="MAX_FILE_SIZE" value="200000000">
     <span id="sprytextfield1">
     <input name="userfile" type="file" id="userfile">
    </span><BR />
    <input type="hidden" name="uploadfile" value="1"/> 
    <input name="upload" type="submit" id="upload" value=" Upload ">
   </p>

我被告知我可以创建自己的php.ini文件并将其保存在cpanel文件管理器上以覆盖一些php.ini值。这就是我现在所拥有的:

//Common local changes:

upload_max_filesize = 20M; // (default 8 - Max, 32)
post_max_size = 20M; // (Average, 20 - Max, 32)
register_globals = Off; // (off by default - you can turn On) 
allow_url_fopen = On; // (off by default - you can turn to On)
memory_limit = 24M; // (default of 8M, Max 32)

但它没有效果!有什么建议吗?

2 个答案:

答案 0 :(得分:3)

我首先使用init_get读取最大上传大小 - 这样做是为了确保您的值被接受: http://php.net/manual/en/function.ini-get.php

如果要使用脚本更改值,可以使用init_set: http://php.net/manual/en/function.ini-set.php

答案 1 :(得分:2)

对.htaccess的更改

.htaccess文件仅适用于Apache Web服务器。它们是附加和更改Apache使用的某些设置的文件,它们放在根文件夹中(下面的所有文件夹都将使用这些设置)。如果Apache使用PHP作为模块,那么您可以将以下设置添加到.htaccess文件中:

php_flag file_uploads On
php_value memory_limit 8M
php_value post_max_size 8M
php_value upload_max_filesize 2M