简体   繁体   English

上传时,在哪里设置php.ini参数?

[英]When uploading, where do I set the php.ini parameters?

In the script where the upload form is, or the script that processes the action? 在上载表单的脚本中,还是处理操作的脚本?

Example parameters: 参数示例:

memory_limit

EDIT : Ok, let me clarify. 编辑 :好的,让我澄清一下。 First, I didn't know the 2nd, 3rd and 4th parameter could not be changed using ini_set() . 首先,我不知道使用ini_set()无法更改第2,第3和第4个参数。 Now, I want to know where exactly I should call the ini_set() function. 现在,我想知道我应该在哪里调用ini_set()函数。 In the form script or the action handling script? 在表单脚本还是动作处理脚本中?

Here's an example to illustrate what I'm looking for: 这是一个示例,说明我在寻找什么:

form.php form.php的

<form action="post.php">
  <input type="text" name="search" />
  <input type="submit" />
</form>

post.php post.php中

<?php //handle search ?>

So under which file must my ini_set() function should go? 那么我的ini_set()函数必须在哪个文件下?

You have to set these parameters initially from php.ini . 您必须最初从php.ini设置这些参数。 You cannot change this from a PHP script except memory_limit , for the remaining Just search for those keys you mentioned in php.ini and change their values. 您不能从memory_limit以外的PHP脚本更改此内容,对于其余的只需搜索您在php.ini提到的那些键并更改其值即可。

For memory_limit you can use following snippet at your processing page handling the uploads like in your case at post.php 对于memory_limit您可以在处理页面上使用以下代码段来处理上载,例如post.php

ini_set("memory_limit","16M");

OR 要么

You can create a .htaccess file at the root directory, if your server support mod_rewrite modules you can change them like this 您可以在根目录中创建一个.htaccess文件,如果您的服务器支持mod_rewrite模块,则可以像这样更改它们

php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200

You set them in the php.ini file, on your server. 您可以在服务器上的php.ini文件中设置它们。 The location of this file depends on your server and its setup. 此文件的位置取决于您的服务器及其设置。 On Linux it can usually be found under the /etc/php*** directory. 在Linux上,它通常可以在/ etc / php ***目录下找到。 On Windows, in the PHP installation directory. 在Windows上,在PHP安装目录中。

  • you can use ini_set to set those parameters dynamicly 您可以使用ini_set动态设置这些参数
  • you can set them in your virtualhost/Location section of apache 你可以在apache的virtualhost / Location部分设置它们
  • you can set them in some htaccess using php_value directive 您可以使用php_value指令在某些htaccess中设置它们
  • you can set them in your php.ini 您可以在php.ini中设置它们

So you have a lot of possibilities depending the one you are using the parameters might be enabled to the whole server, a script in particular, a website in particular, an url in particular. 因此,您有很多可能性,取决于您正在使用的参数可能已在整个服务器上启用,尤其是脚本,特别是网站,特别是url。

Create a .htaccess file in the document root and add the following lines 在文档根目录中创建.htaccess文件并添加以下行

php_value memory_limit 100M
php_value post_max_size 50M
php_value upload_max_filesize 50M

You can set the size you required. 您可以设置所需的大小。

max_file_uploads cannot be changed. max_file_uploads无法更改。 http://bugs.php.net/bug.php?id=50684&edit=1 http://bugs.php.net/bug.php?id=50684&edit=1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM