php文件上传错误1-使用php_ini的正确方法是什么?
我在将pdf上传到服务器时遇到问题。上传的最大文件大小为200万,文件大小超过这个数字,大约为400万。我在这里发现了一篇与我类似的帖子 为了正确使用ini_set命令,我可以从php.net收集到以下信息,我目前正在使用这些信息php文件上传错误1-使用php_ini的正确方法是什么?,php,file-upload,php-ini,Php,File Upload,Php Ini,我在将pdf上传到服务器时遇到问题。上传的最大文件大小为200万,文件大小超过这个数字,大约为400万。我在这里发现了一篇与我类似的帖子 为了正确使用ini_set命令,我可以从php.net收集到以下信息,我目前正在使用这些信息 ini_set('upload_max_filesize', 100000000); ini_set('post_max_size', 110000000); ini_set('memory_limit', 120000000); i
ini_set('upload_max_filesize', 100000000);
ini_set('post_max_size', 110000000);
ini_set('memory_limit', 120000000);
ini_set('max_input_time', 20);
但在我发布的链接中,他们似乎使用了不同的方法(如果他们不只是总结正确的代码)。但我的代码似乎也不能正常工作。我的页面底部有
,上面说上传的最大文件大小仍然是2M。我是否使用了ini_集合的正确语法?或者我上传PDF的问题是其他问题
我处理上传的代码是
//======================pdf upload=====================
if ($_POST['erasePDF'] == "Yes") //checking if erase box was checked and erasing if true
{
if (file_exists($pdf))
{
unlink( $pdf );
$pdf = "";
}
}
print_r($_FILES['pdf']);
if (!empty($_FILES['pdf']['name'])) //checking if file upload box contains a value
{
$saveDirectoryPDF = 'pdfs/'; //name of folder to upload to
$tempName = $_FILES['pdf']['tmp_name']; //getting the temp name on server
$pdf = $_FILES['pdf']['name']; //getting file name on users computer
$test = array();
$test = explode(".", $pdf);
if((count($test) > 2) || ($test[1] != "pdf" && $test[1] != "doc" && $test[1] != "docx")){
echo "invalid file";
}else{
$count = 1;
do{
$location = $saveDirectoryPDF . $count . $pdf;
$count++;
}while(is_file($location));
if (move_uploaded_file($tempName, $location)) //Moves the temp file on server
{ //to directory with real name
$pdf = $location;
}
else
{
echo "hi";
echo '<h1> There was an error while uploading the file.</h1>';
}
}
}else{
$pdf = "";
}
if(isset($_POST['link']) && $_POST['link'] != ""){
$pdf = $_POST['link'];
}
//======================end of pdf upload==============
某些提供程序不允许您在运行时更改某些值。与此相反,可以尝试在真实的php.ini文件中更改它,或者使用.htaccess(用于Apache web服务器)添加配置。您可以在PHP.net文章中找到有关此主题的更多信息: 基于您的故事,example.htaccess
<IfModule mod_php5.c>
php_value upload_max_filesize 100000000
php_value post_max_size 110000000
php_value memory_limit 120000000
php_value max_input_time 20
</IfModule>
php\u值上传\u最大\u文件大小100000000
php_值post_max_大小110000000
php_值内存_限制120000000
php_值最大输入时间20
我当然只是将这些值作为php_ini的一个极端使用,所以我的上传量不可能超过限制,我会将其设置为比我发布的值低得多的值。这不是一个提供商,而是一个内部服务器,但我个人没有访问httpd.conf文件的权限。我想我唯一的选择是使用.htaccess文件。你链接到的页面上没有任何示例,我猜我应该在.htaccess文件中使用的正确语法是“php\u value upload\u max\u filesize'6M'”并设置了AllowOverride?是的,该主机的Apache指令应该具有AllowOverride All
。我将其用作.htaccess文件的内容-我不知道如何正确地将其放在代码括号中[code]允许覆盖所有php值上传\u最大\u文件大小100000000 php值发布\u最大\u大小110000000 php值内存\u限制120000000 php值最大\u输入\u时间20[/code]我在猜测我提出的语法是否正确,或者你是在猜测你给我的代码吗?Allowoverride All
指令应该在httpd.conf
file.Ahh中,所以如果httpd.conf文件中没有设置,那么我唯一的选择就是以某种方式联系服务器管理员?让他更改真实php.ini文件httpd.conf文件中的配置,或者让我访问其中任何一个?
<IfModule mod_php5.c>
php_value upload_max_filesize 100000000
php_value post_max_size 110000000
php_value memory_limit 120000000
php_value max_input_time 20
</IfModule>