I can't understand why my server isn't accepting files larger than 1MB. I am using cpanel and my host has told me that I can't edit my php.ini file directly.
My upload code:
<?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,开发者_C百科 '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> ' . $fileName . '<p><i><u>Size:</u> ' . $fileSize . 'k' . '<p><u>Type:</u> ' . $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>
I was told that I could create my own php.ini file and save it on cpanel file manager to override some of the php.ini values. This is what I have on it at the moment:
//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)
but it has no effect! Any suggestions?
i would start by reading the max upload size with init_get - do this to be sure that your value is being accepted: http://php.net/manual/en/function.ini-get.php
if you want to change the value with your script, you can use init_set: http://php.net/manual/en/function.ini-set.php
Changes to .htaccess
.htaccess files only apply to Apache webservers. They are files that append and change certain settings that Apache uses and they are placed in the root folder (and all folders beneath will use those settings). If Apache uses PHP as a Module, then you can add the following settings to the .htaccess file:
php_flag file_uploads On
php_value memory_limit 8M
php_value post_max_size 8M
php_value upload_max_filesize 2M
精彩评论