2010-03-01 47 views
2

我不明白爲什麼我的服務器不接受大於1MB的文件。我正在使用cpanel,我的主機告訴我,我無法直接編輯我的php.ini文件。文件上傳限於1MB?

我上傳代碼:

<?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

更改爲.htaccess

.htaccess文件僅適用於Apache服務器。它們是附加和更改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